Bill Allombert on Thu, 24 Nov 2005 09:59:02 +0100 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: priority |
On Wed, Nov 23, 2005 at 11:43:23PM +0100, Robert Gerbicz wrote: > Hi! > > Is -5%3=1 correct? In all languages ( c++, basic... ) -5%3 is the > additive inverse of 5%3 so this is -2 This is correct, PARI return the Euclidean remainder which is always non-negative. C/C++ follows the FORTRAN convention whereas the sign of x%n is the product of the sign x and n. This is mathematically a very strange convention, because this make the following implication false: (x-y)%n==0 => x%n==y%n (for example x=-5, y=1, n=3) You call look up he documentation for % using ??% ? ??% %: The expression x % y evaluates to the modular Euclidean remainder of x and y, which we now define. If y is an integer, this is the smallest non-negative integer congruent to x modulo y. Cheers, Bill.