Computing Today - Floating Point Dictionary
|
Software: Ace arithmetic |
||
|
Stephen Renals |
9.8451 and an exponent of 2. This is useful, since: ln 9.84E2 = 2*ln 10 + ln 9.84
Hence the exponent is multiplied by ln 10 (2.30528) to be
added on to the sum at the end. The value of h is then calculated from
the mantissa and the above series is summed. The natural logarithm of a number may therefore be found. log10X = ln x ln 10 EXP calculates the exponential function (exp x ex) of a floating point number. This is achieved by summing the Taylor Approximation to exp x: exp h = l + h + h2 + h3 + h4 + h5 + . . . 21 31 41 51 where nl = n * (n - 1) * (n - 2) * . . . * 1 LN is accurate to around 3 significant figures (SF). The size of the operand is not important, as LN splits the number, as mentioned earlier. EXP is accurate to 5 or 6 SF on numbers between about -2 and 12. It is accurate to 3 or 4 SF when the operand
is between about 12 and 16, or -2 and -4. Above 22 of 23, or below -6 it is not very accurate. ab = exp(b * ln a) F↑ is accurate to between 4 and 6 SF on answers ranging from 0.05 to 1.25 million, and accurate to 2 or 3 SF
on answers up to 500 million or between 0.05 and 0.007. 9x5 - 4x4 + 2x = 3, ie 9x5 - 4x4 + 2x - 3 = 0 type in: : FX (9x5 - 4x4 + 2x - 3) 2DUP 5. FI^ 9. F* 20VER 4. FI^ 4. F* F- 2SWAP 2DUP F+ F+ 3. F- ; REDEFINE X : F'X (45x4 - 16x3 + 2) 2DUP 4. FI^ 45. F* 2SWAP 3. FI^ 16. F* F- 2. F+ ; REDEFINE F'X |
|
|
FLOATING POINT
This dictionary for the Jupiter Ace will let you |
||
|
||
|
The Jupiter Ace has only the most basic of floating point words defined in ROM. However, with a little effort,
a fairly acceptable package of floating point words may be defined.
|
FINPUT will wait for a floating point number to be entered, whereas INPUT (only included for completeness)
will wait for a 16-bit number to be entered. ln m = 2(h + h3 + h5 + h7 + h9 + . . .) 3 5 7 9 where
h = m - l
m + l
This series gives a good approximation of ln m, when m is less than 10. |
|
|
Software: Ace arithmetic |
||
|
Typing SOLVE will leave the |
FX F'X
axm + bxn maxm-l + nbxn-l
sin(ax + b) a*sin (ax + b)
cos(ax + b) -a*cos (ax + b)
tan(ax + b) a/cos2(ax + b)
ax ax * ln a
exp x exp x
ln x l/x
Table 1. Some common functions and their derivatives
|
|
Listing 1. The floating point dictionary for the Ace.
: IT-PAL ;
DEFINER CODE (Page 147 Ace manual)
DOES>
CALL
;
: HEX 16 BASE C! ;
HEX
CODE 2* (N--N*2 )
DF C, (RST 24 )
CB C, 23 C, (SLA E )
CB C, 12 C, (RL D )
D7 C, (RST 16 )
FD C, E9 C, (JP(IY) )
CODE 2/ (N--N/2)
DF C, (RST 24)
CB C, 2A C, (SRA D )
CB C, 1B C, (RR E )
D7 C, (RST 16)
FD C, E9 C, (JP(IY))
DECIMAL
Enter floating point stack rearrangement words
- page 91 Ace manual
: 2ROLL (N--)
DUP 2* ROLL
SWAP 2* ROLL SWAP
;
: 2PICK (N1--FP2)
DUP 2* PICK SWAP
2* 1+ PICK SWAP
;
: 2?DUP (FP--FP,FP if FP=0, FP--FP if FP=0)
2DUP OR
IF
2DUP
THEN
;
DEFINER 2VARIABLE (4 byte variable)
SWAP , ,
DOES>
;
DEFINER 2CONSTANT (4 byte constant)
SWAP , ,
DOES>
2@
;
: FLOAT (N--FP signed UFLOAT)
DUP 0< SWAP ABS
UFLOAT ROT
IF
FNEGATE
THEN
;
: F0< (FP--FLAG page 114 Ace manual)
SWAP DROP 0<
;
: FINPUT (--FP)
BEGIN
RETYPE NUMBER
4102 =
WHILE
DROP
REPEAT
;
|
: INPUT (--N)
BEGIN
RETYPE NUMBER
4181 =
WHILE
2DROP
REPEAT
;
: FERROR? (FLAG--)
IF
8 15421 C! ABORT (ERRNO = 8)
THEN
;
: FI^ (FP1,FP2--FPIFP2; FP2=integer
(not less than zero)
2DUP INT UFLOAT 20VER F-
OR FERROR?
1. 2SWAP 2DUP OR
IF
INT 0
DO
2OVER F*
LOOP
THEN
2SWAP 2DROP
;
: LN (FP--ln(FP))
?DUP 0< FERROR? (can't have In of a negative
number)
DUP 256 / UFLOAT 65. F- (extract the exponent)
2.30528 F* 2SWAP
255 AND 16640 + (a = exponent.1n10, m = mantissa)
2DUP 1. F- 2SWAP 1. F+ F/ (a, h = m-1/m+1)
2DUP 2DUP F* 2OVER
31 3
DO (a, sum, h2, hi-2)
2OVER F. 2ROT 2OVER (a, h2, hi, sum, hi)
I UFLOAT F/ F+ (a, h2, hi, new sum)
2ROT 2ROT 2
+LOOP
2DROP 2DROP 2. F* F+
;
: LOG (FP--log10FP)
LN 2.30258 F/
;
: EXP (FP--exp(fP))
1. 2SWAP 1. (1., h, 1.)
31 1
DO (sum, h, last term)
2OVER I UFLOAT F/ F* (sum, h, this term = last term*h/i)
2ROT 2OVER F+ 2ROT 2ROT
LOOP
2DROP 2DROP
;
: F^ (FPl,FP2--FPl,FP2)
2SWAP LN F* EXP
;
Enter SIN COS TAN SQRT from page 92 of Ace manual
: FX (function equated to 0 by SOLVE)
(redefine to desired function)
(before executing SOLVE)
;
: F'X (derived function of FX for SOLVE)
(redefine before executing SOLVE)
;
: SOLVE (--FP Equates function FX to 0)
1. 26 0 (F`X is derived function of FX)
DO
2DUP FX 20VER F'X F/ F-
LOOP
;
|
|
Please Note ** December 2021
: LN (FP--ln(FP))
?DUP 0< FERROR? (can't have In of a negative
number)
DUP 256 / UFLOAT 65. F- (extract the exponent)
2.30528 F* 2SWAP
255 AND 16640 + (a = exponent.1n10, m = mantissa)
2DUP 1. F- 2SWAP 1. F+ F/ (a, h = m-1/m+1)
2DUP 2DUP F* 2OVER
31 3
DO (a, sum, h2, hi-2)
2OVER F* 2ROT 2OVER (a, h2, hi, sum, hi)
I UFLOAT F/ F+ (a, h2, hi, new sum)
2ROT 2ROT 2
+LOOP
2DROP 2DROP 2. F* F+
;
|