Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

floating point errors?

Eep Quirk
Absolutely Relative
Join date: 15 Dec 2004
Posts: 1,211
03-08-2006 13:14
Why doesn't this increase?
CODE
float num;
default
{
state_entry()
{
num = 99.0;
while(1)
{
num = num + 0.000001;
llSetText((string)num,<1,1,1>,1);
}
}
}


And why DOES this increase?
CODE
float num;
default
{
state_entry()
{
num = 9.0;
while(1)
{
num = num + 0.000001;
llSetText((string)num,<1,1,1>,1);
}
}
}
Masakazu Kojima
ケロ
Join date: 23 Apr 2004
Posts: 232
03-08-2006 13:21
http://secondlife.com/badgeo/wakka.php?wakka=float
From: someone
A 32-bit float is divided into a 24-bit signed "mantissa" ... A 23-bit (1 bit lost for sign) mantissa gives a precision equivalent to approximately 7 decimal digits ... addition or subtraction of two numbers of vastly different magnitudes might yield unexpected results, as the mantissa can't hold all the significant digits.
Eep Quirk
Absolutely Relative
Join date: 15 Dec 2004
Posts: 1,211
03-08-2006 14:31
Ah, so THAT'S what that means. OK, so, then, I guess the next obvious question is when will LSL be getting 64-bit, or whatever, floats?
Seifert Surface
Mathematician
Join date: 14 Jun 2005
Posts: 912
03-08-2006 14:45
From: Eep Quirk
Ah, so THAT'S what that means. OK, so, then, I guess the next obvious question is when will LSL be getting 64-bit, or whatever, floats?
"Double"s I believe.

I doubt it's really worth it generally. Introducing doubles would double the storage and bandwidth associated to any kind of vector, which is a large chunk of the data being shuffled around. It would also make calculations slower.

With sims the size that they are, I don't really see much of a need for the precision given by doubles. If you're talking about a position vector, you need to be up very very high to start seeing distortions (those photos of people looking unwell at some millions of meters altitude). If sims at some point get very very large (say your sim is planet sized) then it starts making sense to be using doubles for positions.
_____________________
-Seifert Surface
2G!tGLf 2nLt9cG