http://www.mactech.com:16080/articles/mactech/Vol.02/02.07/FloatPoint/
here's the first two parts, give me a break.
"12 Kflops - Forth goes inSANE"
You might have noticed my frequent complaints about the slowness of the Apple 80-bit SANE routines and the non-availability of a reasonably fast 32 bit floating point package in Forth systems (and most other programming languages, for that matter, Fortran being the only exception).
The scaling that is necessary if you want to do rapid calculations in Forth (using integer arithmetic) is a nuisance, and it is almost impossible to implement general purpose mathematical routines without floating point. Since I needed to run this machine as fast as possible, I set out to write a set of single precision real arithmetic routines.
IEEE 32-bit real numbers
The number format that we are dealing with is the IEEE standard and defined as follows:
bit 31 (highest bit): sign (0 = positive)
bits 30Š23 : exponent (offset = 127)
bits 22Š0 : fraction part (23 bits with the 24th bit always =1)
That is, a real number has the form
(+/-)1.xxxŠxxx * 2yyy,
where the exponent yyy is obtained by subtracting 127 from the stored exponent; only the fraction part of the mantissa is stored because the integer part is always 1 by definition (otherwise, the fraction part will have to be shifted left and the exponent decreased until the integer part is =1; this is called normalization).
The highest exponent, 255, is reserved for special cases: with zero mantissa it designates positive/negative infinity, and with non-zero mantissa it is a 'no-number' (Not a Number or NaN). This latter case is used to mark the results of undefined or illegal operations, such as 0/0, infinity - infinity, square root (-x), etc. The type of 'non- numberness' is indicated by the value of the mantissa.
Floating point arithmetic is thouroughly treated in D. Knuth's 'The Art of Computer Programming', Vol.2. Taking this excellent book as a guidance, the job to write the single precision routines becomes manageable. We'll first consider addition.