[NCLUG] Forth is amazing!

grant at amadensor.com grant at amadensor.com
Thu Jul 8 14:50:36 MDT 2010

Out of interest in RPN (I love HP calculators) and a constant interest in
new languages that are different, I started playing with Forth, gforth to
be specific.

As a learning tool, I decided to write a little function that calculates
square roots in a rather inefficient manner, by dividing the original
number by an estimated root, and then averaging the estimate with the
result, thereby getting closer to the actual root each time.  Since this
is floating point, some of these numbers never converge exactly.

I ran this in a virtual machine (Debian) under a WinXP host on a couple
year old dual core laptop.  Remember that this is also an interpreted

Here is why it is amazing:
1)  The code is 784 bytes including comments and formatting. 160 bytes raw
2)  It uses NO local or global variables
3)  When I increased the "give up" counter to 10 million (yes, it did 10
million divides and averages) and used a number that never converges, it
still completed in under 2 seconds.  Anything less than 1 million, I can't
perceive the time between the enter key and result.

If you every have heavy math to do in your applications, especially if you
are familiar with RPN, this would be a great tool.

More information about the NCLUG mailing list