TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: David Noon
from: Mike Fisher
date: 1995-12-11 00:24:02
subject: Cube root

Hi David,

On Sunday December 10 1995, David Noon wrote from 2:440/4 to Mike Bilow:

 DN> ========================== CUBRT.PAS =========================

 DN> { A function to calculate cube roots
 DN>   using the Newton-Raphson method.}

 DN> FUNCTION CUBRT(N : REAL) : REAL;

 DN> CONST
 DN>      eps = 1E-12; { Adjust for hardware precision }
 DN> VAR
 DN>      x, xnew : REAL;
 DN> BEGIN
 DN>      IF N = 0 THEN
 DN>           xnew := 0
 DN>      ELSE IF N > 0 THEN
 DN>           xnew := 1
 DN>      ELSE
 DN>           xnew := -1;

 DN>      IF xnew  0 THEN
 DN>      REPEAT
 DN>           x := xnew;
 DN>           xnew := (x + x + N/SQR(x))*(1E0/3E0)
 DN>      UNTIL ABS(x-xnew) >= ABS(x)*eps;

............................~~

 DN>      CUBRT := xnew
 DN> END;

 DN> ==============================================================

(-:  If you change the >= which I have underlined to <= then it works
very well using my compiler, which is Prospero Pascal.  :-)

BTW:  I agree with much of what you wrote about Pascal in general -- but
      it works very well as an applications language for me and the
      compiler I use is very flexible when it comes to adding library
      functions coded in assembler or in Pascal itself.  :-)

Best regards,
Mike.

--- GoldED 2.50+
* Origin: ROOTS (UK!) (2:440/50)
SEEN-BY: 270/101 620/243 711/401 409 410 413 430 807 808 809 934 955 712/407
SEEN-BY: 712/515 517 628 713/888 800/1 7877/2809
@PATH: 440/50 4 141/209 270/101 712/515 711/808 809 934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.