Square Root
Revision as of 16:24, 6 May 2006 by imported>DragoonWraith
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.
scriptname SquareRoot ;originally supplied by Galerion float inputNumber float SqRtValue Begin {appropriate blocktype} ;how inputNumber is set depends on implementation. ;Here it is the number of training sessions the player has had. set SqRtValue to inputNumber/2 set SqRtValue to ( SqRtValue + ( inputNumber / SqRtValue ) ) / 2 set SqRtValue to ( SqRtValue + ( inputNumber / SqRtValue ) ) / 2 set SqRtValue to ( SqRtValue + ( inputNumber / SqRtValue ) ) / 2 set SqRtValue to ( SqRtValue + ( inputNumber / SqRtValue ) ) / 2 End
The inputNumber variable is your input and the SqRtValue is the output variable. In other words, SqRtValue=(inputValue)^(1/2)