ID:2165114
 
Hey I was just wondering, will I ever have floating point errors comparing numbers in BYOND? Lots of other languages have a function to see if a float is approximately the same as another float.

I am using something like the code below and I just need someone to tell me, will it ALWAYS be true?

var/any_integer_ever = 112 //set to any integer and the below will still be true
if(world.time == world.tick_lag * any_integer_ever) return true


So when world.time reaches that many ticks, it will always be true right? I don't have to worry about it?
You'd probably want to do a >= check and not a == check, since there's a very real chance you'll miss your value not because of precision issues (those happen too though), but because of the fact that world.time and world.realtime update on a schedule like everything else and don't always have their values updated down to the tenth of a second, but somewhere nearby.
You will run into floating point error, sadly. You can declare a function that makes use of round() to test approximate equality.
Floating point errors will inevitably happen, as it's the nature if the beast. Floating point is not arbitrary precision, so eventually some information is lost. That's also not getting into funkiness of binary representations, which most floating point numbers use