|
Shippou Oud
The Fox Within
Join date: 11 Jul 2005
Posts: 141
|
07-13-2007 23:25
I wrote a script that calculates the square root of a number below 100 with in 0.4 acuralty. The problem is if I type in a letter instead of a number the script locks up, and spits out "math error"..how can I wright in some code to make sure the values entered are numbers, and not letters befor they are processed?
|
|
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
|
07-14-2007 02:29
From: Shippou Oud I wrote a script that calculates the square root of a number below 100 with in 0.4 acuralty. The problem is if I type in a letter instead of a number the script locks up, and spits out "math error"..how can I wright in some code to make sure the values entered are numbers, and not letters befor they are processed? I take it you mean its accurate to 0.4% accurate. Is that more accurate then llSqrt? I doubt you will get anything more accurate then llSqrt, you will have problems with floating point rounding errors otherwise. Just check to see if the input is zero, if it's zero return zero. // float Sqrt(string str_input) { float in = (float)str_input; if(in > 0.0) return llSqrt(in); return 0.0; } //
_____________________
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
|
|
Shippou Oud
The Fox Within
Join date: 11 Jul 2005
Posts: 141
|
08-01-2007 00:49
I was testing a method of finding square roots the long way by running it threw a loop repeadly. It was off by +-.4 of the cheating way llSqrt();
Your method works well for error handeling =-)
|