Incorrect comparisons and subtractions in roblox script

Why roblox studio scripts got this bug and how to fix it

print(1e+100 + 5 == 1e+100 - 5)

  • Studio 15:32:40.337 true

Floating point inprecisions.

Because of the size of the value you are trying to store, 1e+100 + 5 is stored in the exact same way as 1e+100 - 5, hence when you do a comparison between the 2 you get the same value

Ok, is there any way to fix this?

this isn’t only for roblox
it affects everything (games and other programs)
basically floating point numbers (floats and doubles) have a point where they just become inaccurate
for floats it happens earlier than doubles, because floats only have 4 bytes (32 bits) to work with while doubles have 8 bytes (64 bits)

TL;DR computers can’t be too precise

Not really. Why do you need to compare the 1e100 +/- 5?

not really
this isn’t a roblox issue
this is a computer issue with no fix
you can technically just use more bytes to make your numbers but uh
nobody really does quad precision or higher

I just need to do some big calculations in my game and ints won’t work either?

Nope.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.