[Gambas-user] Modulo operator returns wrong results
Benoît Minisini
gambas at ...1...
Wed Sep 25 03:05:44 CEST 2013
Le 25/09/2013 02:55, Jesus a écrit :
> 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
>
I don't know Python, but the 'Mod' Gambas operator follow the behaviour
of the '%' C operator. Maybe it was not a good idea.
Regards,
--
Benoît Minisini
More information about the User
mailing list