Re: math:mod

new topic     » goto parent     » topic index » view thread      » older message » newer message

Not exactly:

Modulus mathmatically:
- x modulus 0: is undefined.
- x modulus n: is a number in the range 0 .. |n|-1
- where |a| = absolute value of a.

Hence the statement:
- The result is non-negative and has lesser magnitude than divisor.

The mod function uses floored division which would
mean that:

  -9 mod  5 = floor(-1.8) = -2 *  5 +  1  =>  1 
  -9 mod -5 = floor(1.8)  =  1 * -5 + -4  => -4 
   9 mod -5 = floor(-1.8) = -2 * -5 + -1  => -1 
   9 mod  5 = floor(1.8) =   1 *  5 +  4  =>  4 

As -1 mod 5 equals 4 mod 5 and
- -4 mod 5 equals 1 mod 5
the sign of the dividend is irrelevant.

Clearly the mod function is not modulus.
and secondly the documentation is seriously
misleading.

This needs to be fixed.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu