Variable Precision Integer Arithmetic.
Last Up date:
2010 November 17
Recent changes:
Brief list of latest versions
2003 November 20 for www.laforth.com
In 1993 I wanted to convert some powers of ten to hex. Because the
tables I had did not go big enough I decided to write a program to
convert almost any size decimal number to hex. (The only limit was the
size of memory.) I called it DH for Decimal to Hex. All that DH
did for each digit was to multiply what it had by ten and add on
the next digit, until all the digits were done. Initially, I
just looked at the result using the DOS DEBUG command.
That was the start but each day it seemed to need "just one
more feature."
I now have one source but make three versions with
different assembly flags: IA which defaults outputs values in the same base as
the last input. AN which defaults to Hex if the last input was decimal
and visa versa. The name AN came about when I made provisions for alpha
characters to be operators in decimal input mode. The third is a debug
version of AN which shows the approximations in Square Root calculations
- It should output the hex, copying what is on the screen is a bit much.
- It was soon apparent it should convert both ways.
- It should do more than one number at a time.
- Knowing Forth and liking the early HP calculators the values should
obviously be put on a stack.
- Having numbers on a stack cries for arithmetic, and a few Forth stack
manipulation operators.
- If you can input in base 16 why not, like Forth, be able to change the
input base? After all, it just requires the ability to change a
multiplier in the input routine.
Of the four basic arithmetic functions, division is (as we learned in
grade school) the most difficult, and in many ways the most interesting.
In the world of integers, division gives two values for an answer. In
most electronic calculators and even programing languages the
Remainder is treated like an unwanted cousin.
Forth is the only language I am aware of that conveniently provides both
values for an integer divide. (Except Assembly of course.)
The Remainder is valuable, sometimes more valuable than the
Quotient. And sometimes you want both.
Here is an example.
For some time I had felt it would be nice to have an integer calculator.
One that would give two answers to a divide. So I renamed DH to IA
for Integer Arithmetic.
Contact me at:
For comments call, or
e-mail me.
Go to
My Home Page
or
TOP
of this page.