Difference between revisions of "Square Root"

267 bytes added ,  15:56, 14 March 2007
added a note on how to avoid the most common use of sqrt.
imported>DragoonWraith
(commenting comments again)
imported>Proweler
(added a note on how to avoid the most common use of sqrt.)
Line 1: Line 1:
Almost unbelievably, Oblivion does '''not''' include a square root function. Therefore one must use this code to get the square root of a number.
Oblivion does '''not''' include a square root function. Therefore one must use this code to get the square root of a number.


This uses Newton-Raphson approximation, and gives accuracy to two decimal places for numbers less than or equal to 100. Adding more steps to it increases accuracy very quickly.
This uses Newton-Raphson approximation, and gives accuracy to two decimal places for numbers less than or equal to 100. Adding more steps to it increases accuracy very quickly.
NOTE: For a check such as the distance between two points it's not required to actually take the square root. The Forumal of Pythagoras goes A^2 + B^2 = C^2, so instead of "if sqrt(X*X + Y*Y) == C" one can use "If (X*X + Y*Y) == (C*C)", where C is the distance you want to have checked.


This is a [[:Category:Stage_Functions|Stage Function]], and as such must be created as a [[Quest Stages Tab|Quest Stage]] of a global script and called as a function. This assumes a [[Quest]] called Wiki with the variables declared. Therefore, you must modify this code to include the name of your [[Quest]] (assuming it is not Wiki, which it shouldn't be). Alternatively, however, it would not be difficult to incorporate this code into your script directly.
This is a [[:Category:Stage_Functions|Stage Function]], and as such must be created as a [[Quest Stages Tab|Quest Stage]] of a global script and called as a function. This assumes a [[Quest]] called Wiki with the variables declared. Therefore, you must modify this code to include the name of your [[Quest]] (assuming it is not Wiki, which it shouldn't be). Alternatively, however, it would not be difficult to incorporate this code into your script directly.
Anonymous user