Difference between revisions of "Square Root"
Jump to navigation
Jump to search
imported>DragoonWraith (starting this) |
imported>DragoonWraith m |
||
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. | 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 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. | ||
scriptname SquareRoot | scriptname SquareRoot |
Revision as of 16:23, 6 May 2006
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)