Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
EMPTY() Bug - Review
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Problèmes
Divers
Thread ID:
00899617
Message ID:
00899765
Vues:
16
Marvin,

It is not a bug, it's floating point arithmetic on a binary computer. 0.1 can not be expressed exactly in any finite number of binary digits.

If you are using floating point calculations, you should basically never test for exact equality. You must always do tests taking some epsilon value into consideration. ie
epsilon = 0.00001
? abs( a + b + c + d ) < epsilon && result is zero

x = something
y = something else...

? abs( x - y ) < epsilon && .t. if x and y are within epsilon of each other
>Hi I just had a look at this bug, and wanted to warn again:
>
>Try:
>
>clear
>local a, b, c, d,x
>a= -1
>b= -0.1
>c= 1
>d= 0.1
>x= a+b+c+d
>? empty(x) &&The Value should be empty... but FoxPro tells us it isn't
>? x=0 &&This should also deliver a ".f." but it gives us a .t. which is correct
>
>That means...
>
>Be sure not to use empty with unrounded Numeric Values -or-
>don't use empty()
df (was a 10 time MVP)

df FoxPro website
FoxPro Wiki site online, editable knowledgebase
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform