However, Roblox Lua is returning -0.
This is a bug.
This also can cause some problems:
For example, if the variable a has -0 and I use a as an index of a table myTable[a] I could have two different indexes: [0] and [-0] depending on the part of the program which will be referencing the index 0.
The only meaningful difference between 0 and -0 when doing float/double arithmetic (that Iām aware of) is the result when you divide by zero:
print(1 / 0) -- Equal to math.huge
print(1 / -0) -- Equal to -math.huge
Old versions of Lua incorrectly reuse the same constant for both 0 and -0 (whichever is defined first I think) so that snippet might not work in some cases. Negative zero is not a bug, but I still wouldnāt recommend relying too much on its behavior. From a floating point perspective it makes total sense, but I have mixed feelings about tostring exposing it.
Sorry, Iām not expert in JavaScript or Python, but Iāve been working with dozens of programming languages for almost 40 years and believe me, this is the first time Iāve seen -0 as a result of a mathematical operationā¦
But if Roblox staff understands that -0 is normal, you can close this topic.
They tend not to close topics here. Instead you mark a solution so that others can see without opening the topic that a solution has been found. In this instance, marking zeuxcgās or NachtHemdās answer as the solution makes the most sense as both of those provide the information as to why this is not a bug.
This is such a fun piece of trivia because you can dive really deep into computer architecture and design with it.
I think at this point, this behavior is probably encoded at the hardware level. Even more fun is Apple encoded some JavaScript behavior into their chips.