Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Bug : MOD() is mistaken for nDivisor negative
Message
 
 
To
04/01/2005 04:40:03
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00974018
Message ID:
00974040
Views:
16
Fabio,

The MOD() function and % operator both return correct result (modulus). The help incorrectly calls it remainder. See references in Re: MOD() vs % (sql-syntax) Message #973898.

>The definition of Remainder cames from :
>
>Dividend = Quotient * Divisor + Remainder for Divisor<>0
>

>
>On VFP, when Divisor < 0 the result is:
>
>Remainder = CorrectRemainder - Divisor
>
>
>Repro:
>
>CLEAR
>#DEFINE DIVIDEND 10
>#DEFINE DIVISOR   3
>
>? "   Dividend           Divisor      Quotient      Remainder             ";
>+"     Check                    Expected Remainder"
>
>compute( DIVIDEND ,  DIVISOR)
>compute( DIVIDEND , -DIVISOR)
>compute(-DIVIDEND ,  DIVISOR)
>compute(-DIVIDEND , -DIVISOR)
>
>PROCEDURE compute(nDividend , nDivisor)
>
>nQuotient   = INT(m.nDividend / m.nDivisor)
>nremainder  = m.nDividend % m.nDivisor
>
>? m.nDividend , m.nDivisor , m.nQuotient , nremainder , ;
>  m.nQuotient * m.nDivisor + m.nremainder, m.nDividend - m.nQuotient * m.nDivisor
>
>
>On MS SQL the % operation return expected remainders.
>
>Fabio
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform