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

On Monday, 95/12/11, Mike Fisher wrote to David Noon about "Cube root"
as follows:

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

Hi Mike,

You caught a genuine typo I'm afraid. They shouldn't put those 2 keys
so close together on the keyboard. ... ;-)

Actually, that routine can be improved a little in Pascal and a great
deal if reworked in assembler. Remaining in Pascal, if you change the
opening IF statement to

      IF N = 0 THEN
           xnew := 0
      ELSE IF N > 0 THEN
           xnew := (N + 2)*(1E0/3E0)
      ELSE
           xnew := (N - 2)*(1E0/3E0);

you will save one iteration of the REPEAT ... UNTIL loop.

Also, by splitting the IF statement so that the second and third parts
are after a BEGIN, the comparison for xnew  0 can be removed by
putting the REPEAT ... UNTIL loop inside the BEGIN ... END compound
statement.

However, by using a language that can do serious bit-fiddling you can
extract from the argument N those bits that represent the exponent and
treat them as a signed integer, then divide that integer by 3 and use
the quotient for the exponent of the first guess of xnew; for the
mantissa use the mantissa of N multiplied by 0.7937005, or simply
0.7937005, and preserve the sign. The resulting first guess should
converge to 12 significant digits for any value of N inside 6
iterations - typically 3 or 4. This would seem to answer the question
"How does IBM get its pow() function to run 3 times faster than my
optimized C code?"


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

Well, when I first started writing Pascal in the mid 1970's I had
already been coding in PL/I and ALGOL 68 (also FORTRAN, COBOL and
ALGOL 60, but I won't try to justify any of those) for a couple of
years. I'm afraid PL/I was a more powerful language then than Pascal is
now; ALGOL 68 was a more elegant language than any I have seen before or
since, and way ahead of Pascal. Hence my continued support of PL/I (it's
now more powerful than ever) and my continued reservations about Pascal.

Regards

Dave


 * KWQ/2 1.2i * I strangled Linda Lovelace.
--- Maximus/2 3.00
* Origin: DoNoR/2,Woking UK (44-1483-725167) (2:440/4)
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/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™.