24 lines
852 B
Text
24 lines
852 B
Text
Module Checkit {
|
|
Function Root (a, n%, d as double=1.e-4) {
|
|
if n%=0 then Error "Division by zero: 1/0"
|
|
if a<=0 then Error "Negative or zero number"
|
|
if n%=1 then = a : exit
|
|
Flush
|
|
n2=1-1/n%:a/=n%:n%--:Push a
|
|
{ Push 1: For i=1 to n% {Over 2 :Push Number*Number}
|
|
Over 2 : Push n2*Number + a/Number
|
|
Shift 2: Over 2, 2 :if Abs(Number-Number)>d Then loop
|
|
Drop
|
|
} Read a : = a
|
|
}
|
|
Print "square root single"
|
|
Print root(1.3346767~, 2, 1.e-9)
|
|
Print "square double"
|
|
Print root(1.3346767, 2, 1.e-9)
|
|
Print "square root decimal"
|
|
Print root(1.3346767@, 2, 1.e-9)
|
|
Print "internal square root, double"
|
|
Print 1.3346767^(1/2)
|
|
Print sqrt(1.3346767)
|
|
}
|
|
Checkit
|