• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!

[Solved] Same Value Returns Both 0.0 and NULL from Hashtable

Status
Not open for further replies.
Level 18
Joined
Nov 1, 2006
Messages
1,612
The following code returns true for r == 0.0 and r == null. Can anyone tell me why? I would expect that only r==0.0 would return true.

JASS:
local unit t = GetTriggerUnit()
local real r = 0.0

//Save 0.0 value to hashtable
call SaveRealBJ(0.0, GetHandleIdBJ(t), 1, udg_hashTable)

//Other actions occur

//Load value from hashtable
set r = LoadRealBJ(GetHandleIdBJ(t), 1, udg_hashTable)

//Check value
if r == 0.0 then
    call BJDebugMsg("r = 0.0")
endif

if r == null then
    call BJDebugMsg("r is null")
endif

set t = null

I'm just starting to learn hashtables and I have been away from JASS for the better part of a year now, so I apologize if this is hashtable 101 and I'm just late to the party. Either way, any help would be very much appreciated.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,202
Can anyone tell me why?
I can think of 2 possible reasons.
  1. The null value in JASS has an internal value of 0x00000000 and 0.0 represented in a IEEE 32bit float also has a value of 0x00000000.
  2. The real equality comparison operator has strange, non-primitive, behaviour. For example it checks if the numbers are approximately equal with a larger machine epsilon than the real type. There exists reals a and b where by a == b and a != b are both true. The null value might be handled by the equality comparison operator as a special case.
 
Level 19
Joined
Jul 2, 2011
Messages
2,162
there is an easy method to check these values before Booleans.the simplest solution is to convert it into a string and then check the string

if(value=""+null){
Boolean = false;
}

else
{
\\do normal computing
}
 
Status
Not open for further replies.
Top