Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Bug : MOD() is mistaken for nDivisor negative
Message
 
 
À
04/01/2005 04:40:03
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00974018
Message ID:
00974040
Vues:
15
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--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform