Difference between revisions of "Natural Logarithm"
imported>DragoonWraith |
imported>DragoonWraith (forgot to have these direct to the quest) |
||
Line 4: | Line 4: | ||
The list of variables you will need declared in your [[Global Script]]: | The list of variables you will need declared in your [[Global Script]]: | ||
float input (the number whose root you need) | float input ;(the number whose root you need) | ||
float x1 (used internally) | float x1 ;(used internally) | ||
float x3 (used internally) | float x3 ;(used internally) | ||
float x5 (used internally) | float x5 ;(used internally) | ||
float x7 (used internally) | float x7 ;(used internally) | ||
float x9 (used internally) | float x9 ;(used internally) | ||
more x# variables will increase accuracy | ;more x# variables will increase accuracy | ||
float LN (the | float LN ;(the natural log, your answer) | ||
Your input variable need not necessarily be a float, it could be a short or long, but the rest must be floats. 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 the rest must be floats. You are free to rename either, but remember to change the function code. | ||
; supplied by dysesothymteric | ; supplied by dysesothymteric | ||
set x1 to ( ( input - 1 ) / ( input + 1 ) ) | set wiki.x1 to ( ( wiki.input - 1 ) / ( wiki.input + 1 ) ) | ||
set x3 to ( x1 * x1 * x1 ) | set wiki.x3 to ( wiki.x1 * wiki.x1 * wiki.x1 ) | ||
set x5 to ( x3 * x1 * x1 ) | set wiki.x5 to ( wiki.x3 * wiki.x1 * wiki.x1 ) | ||
set x7 to ( x5 * x1 * x1 ) | set wiki.x7 to ( wiki.x5 * wiki.x1 * wiki.x1 ) | ||
set x9 to ( x7 * x1 * x1 ) | set wiki.x9 to ( wiki.x7 * wiki.x1 * wiki.x1 ) | ||
;again, follow this pattern for increased accuracy | ;again, follow this pattern for increased accuracy | ||
set LN to ( x1 + ( x3 / 3 ) + ( x5 / 5 ) + ( x7 / 7 ) + ( x9 / 9 ) ) | set wiki.LN to ( wiki.x1 + ( wiki.x3 / 3 ) + ( wiki.x5 / 5 ) + ( wiki.x7 / 7 ) + ( wiki.x9 / 9 ) ) | ||
;yes, more accuracy means adding more terms here | ;yes, more accuracy means adding more terms here | ||
Revision as of 12:36, 29 May 2006
This is a script for finding the natural logarithm (ln) of a number.
This is a Stage Function, and as such must be created as a 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 declared in your Global Script:
float input ;(the number whose root you need) float x1 ;(used internally) float x3 ;(used internally) float x5 ;(used internally) float x7 ;(used internally) float x9 ;(used internally) ;more x# variables will increase accuracy float LN ;(the natural log, your answer)
Your input variable need not necessarily be a float, it could be a short or long, but the rest must be floats. You are free to rename either, but remember to change the function code.
; supplied by dysesothymteric set wiki.x1 to ( ( wiki.input - 1 ) / ( wiki.input + 1 ) ) set wiki.x3 to ( wiki.x1 * wiki.x1 * wiki.x1 ) set wiki.x5 to ( wiki.x3 * wiki.x1 * wiki.x1 ) set wiki.x7 to ( wiki.x5 * wiki.x1 * wiki.x1 ) set wiki.x9 to ( wiki.x7 * wiki.x1 * wiki.x1 ) ;again, follow this pattern for increased accuracy set wiki.LN to ( wiki.x1 + ( wiki.x3 / 3 ) + ( wiki.x5 / 5 ) + ( wiki.x7 / 7 ) + ( wiki.x9 / 9 ) ) ;yes, more accuracy means adding more terms here
As stated repeatedly in this code's comments, greater accuracy may be achieved by adding more x# variables.