Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Using == vs =
Message
De
06/11/2015 04:31:10
Dragan Nedeljkovich (En ligne)
Now officially retired
Zrenjanin, Serbia
 
 
À
06/11/2015 03:22:29
Walter Meester
HoogkarspelPays-Bas
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Titre:
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows 10
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01627149
Message ID:
01627155
Vues:
75
>Just encountered a bug in our software releated to the use of = when set exact is set to off.
>
>I Know I should be using == in those cases where comparing strings of different lenght, but just a small test made me wonder.
>
>Is there any reason I should not use == for any comparison in VFP? It seems to work for any datatype.
>
>Is there any gotcha using == as a standard?

The gotchas I know of are kind of obsolete:

- when comparing datetimes, where one is coming from a table and one a variable assigned a datetime(), one of them may contain milliseconds and the other not; used to be a problem in VFP 5 or 6, then datetimes lost the milliseconds. That is the format still supports them, but is not stored. They are now always rounded to whole seconds. Still you may hit a table written with one of these older versions and hit those hidden milliseconds (they were never displayed, but you could subtract two seemingly identical datetimes and get a number between -1 and 1).

- comparing floating numbers is unreliable; it actually works but not as expected. Display value of a number is rounded to set("decimals") or whatever way it is formatted; internally it's an IEEE number with 15.5 significant digits. So 7.99...98 may not be equal to 8.0...001 even though both may display as 8.00.

- in collating sequences other than machine, uppercase equals lowercase in ordinary comparison but not in ==
SET COLLATE TO "MACHINE"
?"A"="a", "A"=="a"
SET COLLATE TO "GENERAL"
?"A"="a", "A"=="a"
also some character combinations may be treated as equal when they are not or you may get some weird ordering:
SET COLLATE TO "czech"
?"ch">"c"

That's pretty much all the weird cases I can remember.

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform