Difference between revisions of "Square Root"
Jump to navigation
Jump to search
imported>DragoonWraith (forgot the set inputNumber part) |
imported>DragoonWraith (changed into a Stage Function) |
||
Line 3: | Line 3: | ||
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. | ||
This is a [http://cs.elderscrolls.com/constwiki/index.php/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. 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 | ;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 | |||
[[category: | [[category: Stage Functions]] | ||
[[category: | [[category: Extra Math Functions]] |
Revision as of 18:52, 9 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.
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