[Gambas-user] DIV

Benoît Minisini gambas at ...1...
Thu Jul 12 17:51:18 CEST 2012


Le 12/07/2012 17:44, Jussi Lahtinen a écrit :
>> Doc states, DIV is a synonymous for \ which is the integer division
>> operator.
>>
>
>
> Documentation says "Calculates the quotient of two Integer numbers,
> rounding down".
> And my question was, in other words, why it calculates quotient for only
> integer numbers?
> Output is always integer, but why input should be?
>
> Also why MOD takes only integers, in C you can use fmod() if you want to
> use floats like in math generally.
>
> I think DIV and MOD would have more general usage if they would allow
> floats.
> Only reason I can see to keep DIV accepting only integers is performance,
> but is that really issue for single instruction?
>
> Right now this seems to be so for just historical reasons.
>
> Jussi

This is for performance reasons: '\' (or DIV) operator is faster than '/'.

If you want to use DIV like '/', just use '/'!

And yes, MOD should be able to handle Float (and any other numbers 
implemented as objects, like Complex).

Regards,

-- 
Benoît Minisini






More information about the User mailing list