12 lines
410 B
Plaintext
12 lines
410 B
Plaintext
FUNCTION RootX (tBase AS DOUBLE, tExp AS DOUBLE, diffLimit AS DOUBLE) AS DOUBLE
|
|
DIM tmp1 AS DOUBLE, tmp2 AS DOUBLE
|
|
' Initial guess:
|
|
tmp1 = tBase / tExp
|
|
DO
|
|
tmp2 = tmp1
|
|
' 1# tells compiler that "1" is a double, not an integer
|
|
tmp1 = (((tExp - 1#) * tmp2) + (tBase / (tmp2 ^ (tExp - 1#)))) / tExp
|
|
LOOP WHILE (ABS(tmp1 - tmp2) > diffLimit)
|
|
RootX = tmp1
|
|
END FUNCTION
|