Difference between revisions of "Square Root"
Jump to navigation
Jump to search
fixed some errors
imported>DragoonWraith (changed into a Stage Function) |
imported>DragoonWraith (fixed some errors) |
||
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 [ | 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. | ||
The list of variables you will need: | The list of variables you will need declared in your [[Global Script]]: | ||
input | float input (the number whose root you need) | ||
SqRt | float SqRt (the root, your answer) | ||
You are free to rename either, but remember to change the function code. | Your input variable need not necessarily be a float, it could be a short or long, but SqRt needs to be a float, as few square roots are integers. 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 Wiki.SqRt to input/2 | ||
set SqRt to ( SqRt + ( input / SqRt ) ) / 2 | set Wiki.SqRt to ( Wiki.SqRt + ( Wiki.input / Wiki.SqRt ) ) / 2 | ||
set SqRt to ( SqRt + ( input / SqRt ) ) / 2 | set Wiki.SqRt to ( Wiki.SqRt + ( Wiki.input / Wiki.SqRt ) ) / 2 | ||
set SqRt to ( SqRt + ( input / SqRt ) ) / 2 | set Wiki.SqRt to ( Wiki.SqRt + ( Wiki.input / Wiki.SqRt ) ) / 2 | ||
set SqRt to ( SqRt + ( input / SqRt ) ) / 2 | set Wiki.SqRt to ( Wiki.SqRt + ( Wiki.input / Wiki.SqRt ) ) / 2 | ||
[[category: Stage Functions]] | [[category: Stage Functions]] | ||
[[category: Extra Math Functions]] | [[category: Extra Math Functions]] |