Rounding function broken by recent Roblox update

The purpose is very simple: we’ve had many cases of people being very confused as to why print() prints two numbers identically but they aren’t equal. Fundamentally the fact that tostring() returns the same string for two different numbers is a bug, while convenient at times.

It’s incorrect to think that previously tostring was somehow able to print clean numbers. That’s not the case, it’s just that by virtue of discarding a couple of bits of precision you would sometimes not see the difference. Consider this program that merrily counts until 54.1 until the error becomes too high and becomes visible:

local r = 0 for i=1,1000 do r += 0.1 print(string.format("%.14g", r)) end

I understand that this may be inconvenient, but I don’t think it makes the current tostring behavior any less wrong.

Note that after this change, we will guarantee that tonumber(tostring(v)) is equal to v. This is an important guarantee known as “round-tripping”, and not having this guarantee means that if you try to serialize numbers to a string in text form, you don’t get the same result back which is bad if you ever want to do computations off these numbers. In programming languages, correctness and determinism is important.

You will also find that probably any modern language will have the same behavior as the new behavior of tostring, eg try printing 1.1-1 in JS, Python, Swift, Rust.

10 Likes

Just checked - I’m on 509. And now it prints 35.800000000000004. I guess I wasn’t updated lol

1 Like

and not just that, in the STUDIO terrain modification tool this problem comes with 13 ZEROS

How i found it-
When i was busy making a regular shooting game with some terrain, when I wanted to modify a mountain, i clicked on “grow” and set the strength to 0.6, before that I found that there were 2 glitches, 0.600000000000001 (after 0.6) and 0.700000000000001, justt after the previous glitched one, then it went normal again

Video proof-

mac user here

system specs (if needed)

Did this update affect the engine so that part orientations would be getting rounded off?

We have a part with orientation 89.95 but it’s being set to 90 in Play Solo / Live Game.

In Studio:

In-Game:

(Notice the grey wall at the bottom has lots of gaps)

2 Likes

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