\ Cube root of real number by Newton's method \ ANS compatible version of 10/6/1994 \ This code conforms with ANS requiring: \ The FLOAT and FLOAT EXT word sets \ Non STANDARD words \ FTUCK ( F: x y -- y x y) \ (c) Copyright 1994 Julian V. Noble. Permission is granted \ by the author to use this software for any application provided \ the copyright notice is preserved. \ Non STANDARD words : FTUCK FSWAP FOVER ; : F^2 FDUP F* ; : zdup FOVER FOVER ; \ 1e0 3e0 F/ FCONSTANT 1/3 : x' ( f: n x -- x') \ f" x' = ( n / x / x + 2 * x ) / 3 " FTUCK F^2 F/ FSWAP FDUP F+ F+ 1/3 F* ; : converged? ( F: x' x x' --) ( -- f) F- FABS 1.E-16 F< ; : fcbrt ( f: n -- n^1/3) FDUP F0< ( -- sign-flag) FABS ( f: -- |n|) FDUP FSQRT ( f: -- n first-guess ) BEGIN zdup x' FTUCK \ begin iterative loop CONVERGED? \ stopping criterion UNTIL \ end loop x' \ polish result IF FNEGATE THEN \ apply sign ;