[Gambas-user] Modulo operator returns wrong results

Jesus ea7dfh at ...2382...
Wed Sep 25 02:55:02 CEST 2013


El 25/09/13 02:42, Benoît Minisini escribió:
> Le 25/09/2013 01:23, Jesus a écrit :
>> I've been racking my brain with a simple problem and I've discovered
>> something weird with "Mod" operator, returning wrong results.
>>
>> For example, -3 Mod 800 gives -3, and it should be 797.
>>
>> It's only me or someone else has wrong results?
>>
>
> See
> http://en.wikipedia.org/wiki/Modulo_operation#Common_pitfalls
>
> -3 Mod 800 = -(3 Mod 800)
>
> This is not the mathematical modulus operator.
>

What is it, then? In Python, Modulus operator is % and gives the correct 
results. Also the calculator program has a Mod function which gives the 
expected result.

Anyway I've made a function that mimics the Python modulus, so not a big 
problem.

Thanks

-- 
Jesus Guardon




More information about the User mailing list