Difference between revisions of "Square Root"

Jump to navigation Jump to search
50 bytes removed ,  18:52, 9 May 2006
changed into a Stage Function
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.


  scriptname SquareRoot
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
float inputNumber
set SqRt to ( SqRt + ( input / SqRt ) ) / 2
float SqRtValue
set SqRt to ( SqRt + ( input / SqRt ) ) / 2
set SqRt to ( SqRt + ( input / SqRt ) ) / 2
Begin {appropriate blocktype}
set SqRt to ( SqRt + ( input / SqRt ) ) / 2
;how inputNumber is set depends on implementation.
;Here it is the number of training sessions the player has had.
  set inputNumber to GetPCMiscStat 3
  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)


[[category: Extra_Math_Functions]]
[[category: Stage Functions]]
[[category: Useful_Code]]
[[category: Extra Math Functions]]

Navigation menu