Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Mod() function Bug?
Message
De
22/09/2006 11:39:32
 
 
À
22/09/2006 10:30:37
Calvin Smith
Wayne Reaves Computer Systems
Macon, Georgie, États-Unis
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Divers
Thread ID:
01156435
Message ID:
01156500
Vues:
19
>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.

Calvin,

The implementaion of mod(x, y ) is
x mod y = x - y × floor(x/y)

x = -13
y = 4
? floor(x/y) && -4: here is the surprise
? x - y * floor(x/y) && -13 - 4 * (-4) = -13 + 16 = 3
see on this page http://fixedreference.org/en/20040424/wikipedia/Modular_arithmetic
Gregory
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform