HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

(0.0009==0. and 0.0009!=0.) RETURNS TRUE

03-29-2007, 06:22 AM#1
masda70
Yes, apparently '==' operator in wc3's real's math doesn't do a bitwise evaluation.

Try it yourself, 0.0009==0. , 1.9999 == 2. -103.9991 == -104. , 1.001 == 1. are all true statements in wc3, and this doesn't seem to be because of floating point precision not being able to cope with those numbers.

In fact, bitwise, these numbers are different. Try:
0.0009==0. , 1.9999 != 2. -103.9991 != -104. , 1.001 != 1.
All of these statements return true also!

A reason behind this paradox is perhaps that Blizzard realized that to simplify scripting, and since wc3's coord/dmg/hp,etc math doesn't need to handle that much lower precision, they needed to make the '==' evaluate reals in a
|a-b|<epsilon fashion (or at least that's what I can conclude for now).

This doesn't happen to the '!=' operator which apparently does a bitwise evaluation.

For example, try 45.*1.2 == 54. , it returns true.
Yet 45.*1.2!=54. returns true. Why? Because 1.2 has to be interpreted as
1.1999999 considering 32 bit floating point precision, and bitwise the 45.*1.2 result will differ from the representation of 54.

Other conclusions:

- not(a!=b) performs a bitwise '=='.
- ( unithp == x ) is different a evaluation than not( unithp != x )

EDIT: Oops, I meant to post in the scripting forum.
03-29-2007, 08:36 AM#2
Toadcop
0.0009==0 - this is nothing new ! in true 0.0009 will be 0.000 ! war don't support more then 3 signs after point. but 1.9999 == 2 it's integersting...
inwhole it's not the end of the world !
Quote:
math doesn't need to handle that much lower precision
- in 95% of cases it's true !
03-29-2007, 10:49 AM#3
SFilip
> war don't support more then 3 signs after point
Actually it does, but R2S doesn't seem to convert more than 3 and thus the confusion.
Try it yourself...
Collapse JASS:
    call BJDebugMsg(R2S(bj_PI))
    call BJDebugMsg(R2S(bj_PI*10000.))
03-29-2007, 03:28 PM#4
masda70
Quote:
Originally Posted by Toadcop
0.0009==0 - this is nothing new ! in true 0.0009 will be 0.000 ! war don't support more then 3 signs after point. but 1.9999 == 2 it's integersting...
inwhole it's not the end of the world !
- in 95% of cases it's true !

If it didn't support that precision, then it wouldn't explain why 0.0009!=0. right?
This thread is about how '==' handles equality between 'reals'.

This is a bless anyway, because at least blizzard provided us with two methods of comparing equality between two reals :P.