Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

float

Twisted Pharaoh
if ("hello") {"hey hey";}
Join date: 24 Mar 2007
Posts: 315
01-18-2010 04:04
Hi again how do you explain this?

This debug code is from a simplistic authentification method of mine:
CODE

float rep = (float)llList2String(args, 2) ;
llOwnerSay("rep: "+(string)rep );
llOwnerSay("Ref_Auth: "+(string)Ref_Auth );
llOwnerSay("diff: "+(string)(rep-Ref_Auth)) ;



And I get this:

From: someone

[3:57] Global Scanner Updater: rep: 10992730.000000
[3:57] Global Scanner Updater: Ref_Auth: 10992730.000000
[3:57] Global Scanner Updater: diff: 3.000000



I'm checking the two values and it fails to authenticate, even though they look same.

Worked around with :

if ((string)rep == (string)Ref_Auth)

but still this is weird...
Pete Olihenge
Registered User
Join date: 9 Nov 2009
Posts: 315
01-18-2010 05:15
My guess would be rounding errors: according to my understanding of the replies to my float question (), at seven significant digits you're pretty much on the limit of the precision available for a 32-bit float.
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
01-18-2010 05:23
can't be sure, but I imagine that one of those two is being sent with one more significant digit than it can accurately hold, and it's being truncated. probably at a point where its being converted from a string.
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Twisted Pharaoh
if ("hello") {"hey hey";}
Join date: 24 Mar 2007
Posts: 315
01-18-2010 05:55
I could isolate down to this:

CODE

default
{
state_entry()
{
float a ;
float b ;

a = 78789.25 * 54.07 + 444.34 * 588.09 + 711.21 * 12566.1212 ;
b = (float)"13458600.000000" ;
llOwnerSay((string)a) ;
llOwnerSay((string)b) ;
llOwnerSay((string)(a-b)) ;
}
}


Without Mono:
From: someone

[5:54] Object: 13458598.000000
[5:54] Object: 13458600.000000
[5:54] Object: -2.000000


With Mono:
From: someone

[5:57] Object: 13458600.000000
[5:57] Object: 13458600.000000
[5:57] Object: -2.000000


So it's a Mono issue... I think it is the conversion to string which is innacurate.

Reported:
https://jira.secondlife.com/browse/SVC-5287
Nexii Malthus
[Cubitar]Mothership
Join date: 24 Apr 2006
Posts: 400
01-18-2010 06:36
Oh wow, could you pleaseeee report it to Ji-- Ah, you already did so. :P

(Finally I can post to the Scripting Tips forum! Gah, looks like the scripting tips forum HATES Google Chrome...)
_____________________

Geometric Library, for all your 3D maths needs.
https://wiki.secondlife.com/wiki/Geometric

Creator of the Vertical Life Client
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
01-18-2010 06:52
78789.25 * 54.07 + 444.34 * 588.09 + 711.21 * 12566.1212
= 13458597.716752

llOwnerSay( (string)(13458597.716752) );
LSO: 13458598.000000
MONO: 13458600.000000

but it gets worse....

llOwnerSay( (string)(12566.1212) );
LSO: 12566.121094 <--can anyone see what's wrong with this, wowee
MONO: Object: 12566.120000

something else is screwy and I can't tell what offhand.
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Twisted Pharaoh
if ("hello") {"hey hey";}
Join date: 24 Mar 2007
Posts: 315
01-18-2010 12:40
In C#:

CODE

float y = 12566.1212f;
double z = y;
string x = System.Convert.ToString(z);
MessageBox.Show(x)


I get 12566.12109375 so looks like it's correct, it's because of the way floats are coded.
But if I was converting the float directly it would then show 1256.1212.

In other words,12566.1211 and 12566.1212 are coded the same in float 32 bits.

I think Mono is a bit too "generous" when it comes to rounding values.
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
01-18-2010 12:46
I did a binary fraction generation, and from what I can see, it comes out the same in both, despite showing a difference... I'm wondering if there isn't an additional rounding effect being done on string conversion in MONO... it'd make sense of those results from mono showing a difference of 2 despite being the same when printed.

ETA:
don't ask me why they'd want to do rounding after the fact on strings...
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
01-18-2010 14:23
I've written two functions that should be more reliable than (string)float.

Float2Hex: https://wiki.secondlife.com/wiki/Float2Hex
Scientific Notation: /15/28/28006/1.html

Keep in mind that while these are lossless, they are slower.
_____________________
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