ID:110232
 
Not a bug
BYOND Version:480
Operating System:Windows 7 Home Premium 64-bit
Web Browser:Chrome 9.0.597.98
Applies to:Dream Maker
Status: Not a bug

This is not a bug. It may be an incorrect use of syntax or a limitation in the software. For further discussion on the matter, please consult the BYOND forums.
Descriptive Problem Summary:
When subtracting decimals, it goes nuts after once it goes below 1.

Numbered Steps to Reproduce Problem:

Code Snippet (if applicable) to Reproduce Problem:
mob
var
test4 = 2

Login()
..()

while(test4 >= 0)
test4 -= 0.1
src << test4
sleep(1)


Expected Results:
Not what it's doing below. :(

Actual Results:
1.9
1.8
1.7
1.6
1.5
1.4
1.3
1.2
1.1
1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.0999997
-3.12924e-007


Does the problem occur:
Every time? Or how often?
Every time.
In other games?
Untested.
In other user accounts?
Untested.
On other computers?
Untested.

When does the problem NOT occur?
When round() is used.

Did the problem NOT occur in any earlier versions? If so, what was the last version that worked?
I've only tested it on 479 and 480, and it happens in both of those versions.

Workarounds:
Use round() to the approximate decimal.
Changing 0.1 to, say, 0.01 REALLY makes it go bananas.
I'm terrible at math. Is this a bug, or intended?

Why does BYOND do this thing?
BYOND uses single-precision floating point to handle numbers. Because this is a binary and not a decimal storage format, numbers like 0.1 cannot be represented exactly and some rounding error will always occur. If you want to keep your results close to increments of 0.1, you should always round to the nearest 0.1 at the end of the calculation. Alternatively when you compare to values like 0 you can simply check if the value is close to 0. There are many techniques for coping with rounding error, but the bottom line is it is not a bug.
Ah, alright then.