Square Root
Revision as of 18:52, 9 May 2006 by imported>DragoonWraith (changed into a Stage Function)
Almost unbelievably, 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 is a Stage Function, and as such must be created as a Quest Stage of a global script and called as a function. Alternatively, however, it would not be difficult to incorporate this code into your script directly.
The list of variables you will need:
input SqRt
You are free to rename either, but remember to change the function code.
;originally supplied by Galerion set SqRt to input/2 set SqRt to ( SqRt + ( input / SqRt ) ) / 2 set SqRt to ( SqRt + ( input / SqRt ) ) / 2 set SqRt to ( SqRt + ( input / SqRt ) ) / 2 set SqRt to ( SqRt + ( input / SqRt ) ) / 2