23 lines
1.1 KiB
Plaintext
23 lines
1.1 KiB
Plaintext
window 1
|
|
|
|
local fn NthRoot( root as long, a as long, precision as double ) as double
|
|
double x0, x1
|
|
|
|
x0 = a : x1 = a /root
|
|
while ( abs( x1 - x0 ) > precision )
|
|
x0 = x1
|
|
x1 = ( ( root -1.0 ) * x1 + a / x1 ^ ( root -1.0 ) ) /root
|
|
wend
|
|
end fn = x1
|
|
|
|
print " 125th Root of 5643 Precision .001",, using "#.###############"; fn NthRoot( 125, 5642, 0.001 )
|
|
print " 125th Root of 5643 Precision .001",, using "#.###############"; fn NthRoot( 125, 5642, 0.001 )
|
|
print " 125th Root of 5643 Precision .00001", using "#.###############"; fn NthRoot( 125, 5642, 0.00001 )
|
|
print " Cube Root of 27 Precision .00001", using "#.###############"; fn NthRoot( 3, 27, 0.00001 )
|
|
print "Square Root of 2 Precision .00001", using "#.###############"; fn NthRoot( 2, 2, 0.00001 )
|
|
print "Square Root of 2 Precision .00001", using "#.###############"; sqr(2) // Processor floating point calc deviation
|
|
print " 10th Root of 1024 Precision .00001", using "#.###############"; fn NthRoot( 10, 1024, 0.00001 )
|
|
print " 5th Root of 34 Precision .00001", using "#.###############"; fn NthRoot( 5, 34, 0.00001 )
|
|
|
|
HandleEvents
|