Game Development Community

Type Insensitivity

by Seth Willits · in Torque Game Engine · 11/20/2004 (6:22 pm) · 5 replies

Ok, so today I had time to do stuff so I've been reading through the documentation. To my amazement, I found a fundamental bug or something I'm clearly misunderstanding:

I entered the script at the top of this page in the docs and it actually printed different! What's up with that?!

The exact line I entered was:
if ("1.2" == 1.2) { echo("Same"); } else { echo("Different"); }

Totally 100% repeatable.


If I don't use a decimal, ie if I use ("1" == 1) then it works fine. It seems there's an issue with floating point conversions.

#1
11/21/2004 (2:15 am)
Seth, just to give this the benefit of the doubt, I triple sanity-checked with various versions of Torque... copy-pasted the exact line of code above and "Same" is printed every time. If you copy-paste the exact line of code above, does it still happen for you?
#2
11/21/2004 (2:32 am)
Hmmm, I was just about prepared to come say all is fine here, and then I got a surprise....


Exact log of it....



----------- Starting GTC_SSP Interface ----------

CanvasToggle: CurGUI = 1468 Win = ConDlgWin
Con Input --> if ("1.2" == 1.2) { echo("Same"); } else { echo("Different"); }
Same
Con Input --> if ("1.201020901" == 1.201020901) { echo("Same"); } else { echo("Different"); }
Same
Con Input --> if ("1.201020901" $= 1.201020901) { echo("Same"); } else { echo("Different"); }
Different
Con Input --> if ("1.2" $= 1.2) { echo("Same"); } else { echo("Different"); }
Same
Con Input --> quit();


Now I'm confused. Even though the third example is obviously a String declare and a numeric declare, I was pretty sure they were "String Equal", and it came up different. So, I figured I somehow had it wrong all this time and it would return different on the fourth one. SURPRISE!!! Don't ask me for my thoughts, lol, I no longer have any idea who is right, only what I thought was right.

DOH!
#3
11/21/2004 (7:36 am)
@Josh, absolutely. But, you can't copy and paste in to Torque anyway (or at least I can't) so I still have to type it in. But trust me, I'm a programmer, I can type a line of code the same.

www.freaksw.com/torque/Console.png
#4
11/21/2004 (7:39 am)
@Josh - Did you try it in 1.3 on Mac OS X?
#5
11/21/2004 (10:09 am)
You can copy-paste, but maybe just on Windows. :)

Actually no, I didn't try it on OS X. It shouldn't matter a bit, but something must be different, so .. maybe. I will test it out in about 30 minutes when I get into the office. Thanks for pointing this out in any case, very interesting.

Gonzo, I'm pretty bleary-eyed this morning, but.. that looks awfully weird too. Have to check it out...