Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Turn negative into positive
Message
De
10/12/2013 04:30:12
 
 
À
09/12/2013 14:59:46
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01589528
Message ID:
01589645
Vues:
74
>
>Of course... that formula you gave has a risk of numeric overflow...

The formula I gave was
N = -N
I find one exception where the negative value results in the same value.

I'm not convinced overflow comes in

(1) the value is -2^31 and (2) you force the value to be contained in a 4 byte signed integer
n = 0x80000000
?'n = ', n	&& 2147483648
?'-n = ', -n	&& -2147483648
n = bitor(n, 0) && force a 4 byte signed integer
?'bitor = ', n	&& -2147483648
x = -n
?'-n = ', x	&& -2147483648
?'abs', abs(n)	&& -2.1474E+9

? ' x == -x ', x == -x  && TRUE
Update - and yes - I know why
Gregory
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform