Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Mod() function Bug?
Message
From
23/09/2006 02:31:22
 
 
To
22/09/2006 10:30:37
Calvin Smith
Wayne Reaves Computer Systems
Macon, Georgia, United States
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Miscellaneous
Thread ID:
01156435
Message ID:
01156674
Views:
20
>The mod command gives stange results when done this way:
>Mod(-13,4). I would expect this to return either 1 or -1 but it returns 3.
>Visual Basic return -1 for this command but Ruby return the same thing as VFP. Can someone explain this to me.... Thanks.

None bug.
This is a different definition ( many exists )

The VFP,Ruby,Excel,... definition is the best because it return 4 different results
with the 4 sign cases
? MOD(+13,+4) && 1
? MOD(+13,-4) && -3
? MOD(-13,+4) &&  3
? MOD(-13,-4) && -1
<-pre>

Another definition is (SQL SERVER,...):
... return the MINIMAL absolute remainder with the divisor sign
<pre>

? MOD2(+13,+4) &&  1
? MOD2(+13,-4) && -1
? MOD2(-13,+4) &&  1
? MOD2(-13,-4) && -1


FUNCTION MOD2(n,d)
	RETURN SIGN(m.d)*MOD(ABS(n),abs(d))
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform