I know that floating point isn’t exact. If you didn’t know that, you need to read http://floating-point-gui.de/
I’m trying an example from https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/…
local f = 0.1;
local sum = 0.0;
for (local i = 0; i < 10; ++i) {
sum += f;
}
server.log("sum = " + sum + "\n");
local product = f * 10.0;
server.log("product = " + product + "\n");
if (sum == product) {
server.log("Equal\n");
}
else {
server.log("Not equal\n");
}
And it’s logging the following:
2017-08-15 13:54:05 +01:00 [Agent] sum = 1
2017-08-15 13:54:05 +01:00 [Agent] product = 1
2017-08-15 13:54:05 +01:00 [Agent] Not equal
I don’t have a problem with the “Not equal”. My question is this:
What are the semantics for printing floating point numbers with server.log()?
It displays both floating point numbers as 1
. If I try similar squirrel code locally (with print
instead of server.log
), and I throw an exception, I get:
LOCALS
[product] 1
[sum] 1.0000001192093
[f] 0.10000000149012
So I know that the precision’s in there. Where did it go?