Talk:Continued fraction/Arithmetic/G(matrix ng, continued fraction n1, continued fraction n2): Difference between revisions

mNo edit summary
Line 12:
 
::Right, but the problem is that there are (at least) two different definitions of division / remainder for negative numbers. For example, in C99/Java, (-151) / 77 is -1 and (-151) % 77 is -74, but in Python/Ruby, (-151) / 77 is -2 and (-151) % 77 is 3. --[[User:Spoon!|Spoon!]] 20:27, 11 March 2013 (UTC)
 
:::[[http://calculator.tutorvista.com/math/418/quotient-remainder-calculator.html]] says the Quotient is -2 and the Remainder is -74. So let's hope the students being tutored never have to divide negative rational numbers. I'd have to pay for tutoring to get an explanation, so I won't bother (though there is a money back guarantee if I'm not satisfied, and I can't see how I would be). [http://blogs.msdn.com/b/ericlippert/archive/2011/12/05/what-s-the-difference-remainder-vs-modulus.aspx what-s-the-difference-remainder-vs-modulus.aspx] gives a good explanation of the difference between remainer and modulus functions, (% in ruby is a modulus function). Quoting from [http://blogs.msdn.com/b/ericlippert/archive/2011/12/05/what-s-the-difference-remainder-vs-modulus.aspx what-s-the-difference-remainder-vs-modulus.aspx] "The net result here is that integer division rounds towards zero. That should make sense; we want 123/4 to be 30 with a remainder of 3, not 31 with a remainder of -1. Similarly, we want -123/4 to be -30, not -31! It would be bizarre to say that 4 goes into 123 30 times but goes into -123 -31 times! One expects that changing the sign of a term changes the sign of the result; it does not change the magnitude of the result." I think the other result comes from a linguistic extension of Euclid's algorithm with no consideration for the "bizarre" mathematical logic resulting. So my view remains:
::::151/77 is 1 remainder 74 and is [1;1,24,1,2]
::::-151/77 is -1 remainder -74 and is [-1;-1,-24,-1,-2] or -[1;1,24,1,2] (not [-2;25,1,2])
:::the other definition works, but is it pretty?--[[User:Nigel Galloway|Nigel Galloway]] 13:27, 12 March 2013 (UTC)
2,171

edits