Aaron Levy
Medicated Lately?
Join date: 3 Jun 2004
Posts: 2,147
|
07-25-2004 21:24
I'm getting sick of my friggin' prims ending up with positions like 5.00005 and crap like that. Especially when I'm not touching the damn things and the script in them is moving them in increments of .25, NOT .00005!!!!
I've got one prim here that according to it's position in-world is in the right spot. When the script looks at it, it's at 249.0008 and no amount of me tinkering with it is getting rid of the damn .0008.
Why in the HELL do we need it that precise?
|
Almarea Lumiere
Registered User
Join date: 6 May 2004
Posts: 258
|
07-25-2004 21:56
Floating point numbers. Always a bad idea.
|
Aaron Levy
Medicated Lately?
Join date: 3 Jun 2004
Posts: 2,147
|
07-25-2004 21:58
No choice when dealing with vectors, unless someone knows a trick I don't.
|
Malachi Petunia
Gentle Miscreant
Join date: 21 Sep 2003
Posts: 3,414
|
07-25-2004 23:30
The trick that you may be looking for is to save the original position in order that you may return the object to that exact spot. I'm just guessing as I don't know what you are trying to do.
Also, saving the original position and making displacements from there should reduce compounding of floating point errors.
|
Cray Levy
Member
Join date: 7 Jul 2004
Posts: 33
|
07-26-2004 00:11
Aaron, fixed point numbers 
|
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
|
07-26-2004 00:11
since the old script forum got nuked i'll have to go into this.
Floats in LSL are IEEE 32-Bit Floats it breaks down to: 1 bit for sign 1 bit for the sign of the Exponent 7 bit for the Exponent 23 bit for the Mantissa
1 > Mantissa >= 0 127 >= Exponent >= -128
so how the float works is it multiplies the Mantissa by 2 raised to the exponent.
Mantissa * 2^exponent
take a number like 248. It's Exponent would be 8 this means that 8 bits of the Mantissa will be used to represent the numbers integer value. This leaves 15 bits to represent the fractional value.
so the smallest incremint of change these numbers can represent is 2^(Exponent - 23). In this case it's 2^(8-23) = 2^(-15) = 1/32768 = 0.000030517578125
so for your number to be .00005 off is no great supprise.
this is why you should avoid adding small floats to large ones.
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river. - Cyril Connolly
Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence. - James Nachtwey
|
Tiger Crossing
The Prim Maker
Join date: 18 Aug 2003
Posts: 1,560
|
07-26-2004 10:33
And you can always do some rounding functions to remove what errors DO creap in.
_____________________
~ Tiger Crossing ~ (Nonsanity)
|
Almarea Lumiere
Registered User
Join date: 6 May 2004
Posts: 258
|
07-26-2004 10:47
You'd think the Real Estate developers would be hawking their south-west corner plots: Great Land for Building! Four Extra Bits of Precision!!!
And you guys wonder why your coordinates drift when you're up in the air over 512 meters...
Floating point numbers. Just say NO!
--Almarea
|