Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Bug : MOD() is mistaken for nDivisor negative
Message
From
04/01/2005 04:40:03
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Other
Title:
Bug : MOD() is mistaken for nDivisor negative
Miscellaneous
Thread ID:
00974018
Message ID:
00974018
Views:
65
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
Next
Reply
Map
View

Click here to load this message in the networking platform