Dec 082017
 
VP Planner Software Floating Point v. 1.02 by Jack Brown, for F-PC Forth compiler. Includes bug fix over version 1.01.
File VPSFP102.ZIP from The Programmer’s Corner in
Category Forth Source Code
VP Planner Software Floating Point v. 1.02 by Jack Brown, for F-PC Forth compiler. Includes bug fix over version 1.01.
File Name File Size Zip Size Zip Type
DEARJACK 1388 693 deflated
FPCOM1.SEQ 14330 3650 deflated
FPCOM2.SEQ 13434 4572 deflated
FPMATH.SEQ 1967 379 deflated
FPNUMBER.SEQ 12107 3073 deflated
FPTOOL.SEQ 2469 1157 deflated
FPTRANS.SEQ 16907 5236 deflated
FPVECTOR.SEQ 3281 1472 deflated
FRECURSE.SEQ 2185 896 deflated
NAN.SEQ 14461 2923 deflated
README.101 4101 1786 deflated
SFPPRIM1.SEQ 52645 8870 deflated
SFPPRIM2.SEQ 25149 5704 deflated
VPFLOAT.DOC 18672 5015 deflated
VPSFLOAT.SEQ 1295 597 deflated

Download File VPSFP102.ZIP Here

Contents of the VPFLOAT.DOC file



Version 1.01 VP-Planner software floating point for Zimmer's F-PC

Preliminary Documentation for VP-Planner floating point.

Modified April 6, 1989 by Jack Brown
Modified May 14, 1989 by Jack brown

/*
Kent Brothers and Stephenson Software Ltd. are making these floating
point routines available to the Forth language community to further the
growth of Forth as an application development language. It is licensed
for incorporation into programs (with or without modifications) with no
fee as long as the following notice is displayed on screen and in the
documentation:

VP-Planner floating point routines copyright 1985-1989
Kent Brothers, Stephenson Software Ltd.

The source code may be distributed free of charge provided this entire
message (including the notice) is left at the top.
*/

WARNING: There may be a problem with the way I implemented
FLOATING and DOUBLE for switching between floating
and double number input. The compiler seems to get
confused occasionally when FLOADing with FLOATING
point numeric input set. I didn't have time to check
out the problem so beware.


Glossary of VP-Planner software floating point words.
-----------------------------------------------------

We have provided ALIASes for floating point functions that have more
than one name in common usage. Glossary is not sorted in any meaningful
order!


F0 ( P: -- addr )
Returns the address of a variable which points to the base of
the floating point stack.

FSP0 ( P: -- addr )
Points to the base of the floating point stack.

FP ( P: -- addr )
FSP ( P: -- addr )
Returns the address of a variable which points to the top of
the floating point stack.

[email protected] ( P: -- addr )
Returns the address of the current top of the floating point
stack.

FP! ( F: -- )
FCLEAR ( F: -- )
Resets the floating point stack pointer to FSP0 .
In simple language it clears the floating point stack.

?FSTACK ( -- )
Checks the floating point stack for overflow or underflow. An
ABORT" error message is printed for either case.

FDROP ( F: r -- ) Drop a f.p. number from the f.p. stack.

FARRAY Create an array of floating point numbers.
( F: rn ... r1 r0 -- ) ( P: n+1 -- ) ( compiling )
( P: k -- rk_addr) ( executing)
Example:
1.30 45.0 17.0 19.1 4 FARRAY TABLE
0 TABLE .. 19.1
3 TABLE .. 1.30
4.4 3 TABLE F!
3 TABLE .. 4.4


FCONSTANT ( F: r -- ) ( compiling )
Create a floating point constant. Analogous to CONSTANT .

FVARIABLE ( -- ) ( compiling )
Create a floating point variable. Analogous to VARIABLE .

FVALUE ( F: r ; FVALUE name )
A word for creating floating point values similar to VALUE
An FVALUE may be changed using the F!> assignment operator
and incremented using the F+!> operator.
Example:
12.56 FVALUE RATIO \ creates the FVALUE called RATIO
\ and initializes it to 12.56
RATIO \ 12.56 is pushed to top of fp stack.
11.22 F!> RATIO \ 11.22 is assigned to RATIO
2.0 F+!> RATIO \ RATIO is incremented by 2.

FVALUES ( P: n -- ) ( F: -- ; name-1 name-2 ... name-n)
Create n FVALUES floating point values called name-1 ... name-n
all initialized to 0.0
Example:
3 FVALUES LENGTH WIDTH HEIGHT

PI ( F: -- pi )
An fconstant that leaves 3.1415926358979323846 on the floating
point stack.

2PI ( F: -- pi*2 )
An fconstant that leaves 6.28.... or 2pi on the floating point stack.

PI/4 ( F: -- pi/4 )
An fconstant that leaves pi/4 on the floating point stack.

PI/2 ( -- addr )
An fconstant that leaves pi/2 on the floating point stack.

1. ( F: -- 1.0 )
F1.0 ( F: -- 1.0 )
Push a floating point 1.0 onto the floating point stack.

0. ( F: -- 0.0 )
F0.0 ( F: -- 0.0 )
Push a floating point 0.0 onto the floating point stack.

F* ( F: r1 r2 -- r3 )
Replace the two numbers at the top of the f.p. stack with
the product of the two numbers.

F+ ( F: r1 r2 -- r3 )
Replace the two numbers at the top of the f.p. stack with
the sum of the two numbers.

F- ( F: r1 r2 -- r3=r1-r2 )
Subtract the top f.p. number from the second f.p. number.
Replace the top two numbers with that difference.

F\- ( F: r1 r2 -- r3=r2-r1)
As above but reverses arguments. Used in COMPLEX.SEQ

F/ ( F: r1 r2 -- r3 )
Divide the second f.p. number by the top f.p. number. Replace
the top two numbers by the quotient.

FABS ( F: r1 -- |r1| )
Clear the sign bit of the floating point value at the top of
the f.p. stack, yielding a positive value.

FNEGATE ( F: r1 -- r2 )
Reverse the sign of the number at the top of the f.p. stack.

FSIGN ( P: -- n ) ( F: r -- r )
Leave sign and exponent as n if nonzero, otherwise leave 0.


FSQRT ( F: r1 -- r2 )
Replace the value at the top of the f.p. stack with its square
root.

LOG10 ( F: r1 -- r2 )
FLOG ( F: r1 -- r2 )
Replace the value at the top of the floating point stack with
its base 10 logarithm.

LN ( F: r1 -- r2 )
FLN ( F: r1 -- r2 )
Replace the value at the top of the floating point stack with
its natural logarithm.

1/X ( F: r1 -- r2 )
1/F ( F: r1 -- r2 )
Replace the value at the top of the floating point stack with
its reciprical.

2.* ( F: r1 -- r2 )
F2* ( F: r1 -- r2 )
Multiply the f.p. number on the top of the f.p. stack by 2.0 .

2./ ( F: r1 -- r2 )
F2/ ( F: r1 -- r2 )
Divide the top f.p. number by 2.0 .

2SCALE ( F: r1 -- r2 ; n -- )
F2**N* ( F: r1 -- r2 ; n -- )
Multiply the top f.p. number by 2 raised to the nth power. n
may be either positive or negative.

FLOAT ( F: -- r ; d -- )
Pop the double integer from the parameter stack and push it onto
the f.p. stack, converting it to a floating point number.
Note: Value stored in variable DPL is used to scale
the double number.

N>R ( F: -- r )( P: n -- )
S>F ( F: -- r )( P: n -- ) Do we really need this many aliases?
IFLOAT ( F: -- r )( P: n -- )
Convert single number to floating point number.


D>R ( F: -- r )( P: d -- )
D>F ( F: -- r )( P: d -- )
Convert double number to floating point number.

F>D ( F: r -- )( P: -- d )
FIX ( F: r -- )( P: -- d )
Round the number at the top of the floating point stack to an
integer, using the "round to even" rule. Pop the result from the
floating point stack and push the double number result onto the
parameter stack.

INT ( F: r -- ) ( P: -- d )
Round the number at the top of the floating point stack toward
zero. Pop the result and push the double number onto the parameter
stack.


INTFRAC ( F: r -- [r] r-[r] )
Round the top number r on the fp stack to an integer [r]
Leave [r] as second element and r - [r] as top of fp stack.

F->FIS ( F: r -- )
( P: -- qf qi FS 0 ) if 2^-64 <= |r| < 2^64 )
( P: -- 0 -1 ) if r = 0
( P: -- FS 1 -1 ) if 0 < |r| < 2^-64 )
( P: -- FS 2 -1 ) if |r| >= 2^64 )
Used for fast number formating.
If 2^-64 <= |r| < 2^64, converts r to to an unsigned
octuple-precision integer multiple of 2^-64. The two
quadruple precision integers qf and qi are the fractional
and integral portions of r, respectively, and FS denotes the
sign of r, with -1 indicating negative and 0 positive. A 0
flag is returned as the top item if |r| is within this
range. If not, a -1 flag is returned as the top item, with
the second item indicating the magnitude of r: 0 if r = 0,
1 if |r| < 2^-64, and 2 if |r| > 2^64. In the latter two
cases, the sign of r is also returned.

FDUP ( F: r -- r r )
Duplicate the number at the top of the f.p. stack.

FOVER ( F: r1 r2 -- r1 r2 r1 )
Push a copy of the second item on the parameter stack onto the
parameter stack.

FSWAP ( F: r1 r2 -- r2 r1 )
Exchange the top two items on the f.p. stack.

FROT ( F: r1 r2 r3 -- r2 r3 r1 )
Rotate the top three items on the floating point stack, bringing
the third item to the top.

F-ROT ( F: r1 r2 r3 -- r3 r1 r2 )
Rotate the top three items on the floating point stack, moving the
top item to the third position.

FNIP ( F: r1 r2 -- r2 )
Remover the second item from the floating point stack.

FTUCK ( F: r1 r2 -- r2 r1 r2 )
Place a copy of the top item on the floating point stack under the
second item on the f.p. stack.

FPICK ( F: rn rn-1 ... r0 -- rn rn-1 r0 rn ; n -- )
Push a copy of the n-th item on the floating point stack onto the
floating point stack. Counting begins at 0.

F0= ( F: r -- ; -- f )
Pop and test the f.p. number at the top of the f.p. stack.
If the number was a floating point zero, push a true flag on
the parameter stack. Otherwise push a false flag (0).

F0< ( F: r -- ; -- f )
Pop and test the f.p. number at the top of the f.p. stack.
If the number is less than zero, push a true flag on the parameter
stack. Otherwise push a false flag.

F0> ( F: r -- ; -- f )
Pop and test the f.p. number at the top of the f.p. stack.
If the number is greater than zero, push a true flag on the
parameter stack. Otherwise push a false flag.

F= ( F: r1 r2 -- ; -- f )
If the top two elements on the f.p. stack are equal, return a
true flag. Otherwise return a false flag. In either case, the
top two elements on the f.p. stack are popped.

F< ( F: r1 r2 -- ; -- f )
Compare the top two elements on the f.p. stack. If the second
number is less than the first, return a true flag. Otherwise
return a false flag. In either case the f.p. stack is popped
twice.

F> ( F: r1 r2 -- ; -- f )
Compare the top two elements on the f.p. stack. If the second
number is greater than the first, return a true flag. Otherwise
return a false flag. In either case the f.p. stack is popped
twice.

FMIN ( F: r1 r2 -- r3 )
Replace the top two elements on the f.p. stack by the algebraically
smaller of the two.

FMAX ( F: r1 r2 -- r3 )
Replace the top two elements on the f.p. stack by the algebraically
larger of the two.


LEF! ( P: seg addr -- ) ( F: r -- )
Store temp-real (80bit) floating point number to memory
at seg addr.

[email protected] ( P: seg addr -- ) ( F: -- r )
Fetch temp-real (80bit) floating point number from memory
at seg addr to top of floating point stack.

LDF! ( P: seg addr -- ) ( F: r -- )
Store temp-real (80bit) floating point number on top of the
fp stack to memory at seg addr as a (64bit) IEEE double
precision number.

[email protected] ( P: seg addr -- ) ( F: -- r )
Fetch (64bit) IEEE double precision floating point number from
memory at seq addr to the top of the floating point stack as a
temp-real (80bit) floating point number.


[email protected] ( F: -- r ; addr -- )
[email protected] ( F: -- r ; addr -- )
Push the f.p. number pointed to by the address at the top of the
parameter stack onto the f.p. stack. The address is popped from
the parameter stack.

EF! ( F: r -- ; addr -- )
F! ( F: r -- ; addr -- )
Store the f.p. number at the top of the f.p. stack into memory
beginning at the address specified at the top of the parameter
stack.

FLITERAL ( F: r -- )
Pop a number from the f.p. stack and create an in-line fliteral
floating point number. Used while compiling.


+INF ( F: -- +infinity )
Floating point representation of + infinity.

-INF ( F: -- -infinity )
Floating point representation of - infinity.

FERR ( F: -- r )
Floating point representation of error condition.

FNA ( F: -- r )
Floating point representation of not a number, NA.

NAN Encodings:

Encodings: Long Real (Double) Extended (Temporary)
+INF 7FF0 0000 0000 0000 7FFF 8000 0000 0000 0000
-INF FFF0 0000 0000 0000 FFFF 8000 0000 0000 0000
ERR 7FF8 0000 0000 0000 7FFF C000 0000 0000 0000
or FFFF C000 0000 0000 0000
NA FFF8 0000 0000 0000 FFFF E000 0000 0000 0000
String 7FF8 0LLL AAAA SSSS 7FFF 0LLL AAAA SSSS 0000
Range not used 7FFF 40C1 ROW1 00C2 ROW2

See NAN.SEQ for more information.

NAN Checking words.

Note: All error conditions are returned as NAN's. It is the users
responsibilty to use the following words or extensions to check that
user written functions have valid floating point stack inputs. If
necessary the user can generate special NAN error codes to propagate
error information to calling routines.

?NAN ( P: -- flag)( F: r -- r )
Checks the type N of number X on the FP stack:
flag = 0 not a NAN valid number!
1 NA Not Available.
2 ERR Error condition.
3 string ( used in spread sheet application )
4 range ( used in spread sheet application )
-1 miscellaneous NAN ( You can generate your own NAN's ! )


?NONAN1 ( P: -- flag ) ( F: r -- r )
Leave a true flag on the parameter stack if the top number
on the fp stack is a valid number. Valid numbers include
0, Normal, Dnormal, Unnormal. Invalid are Infinity, NANs,
and Empty.

?NONAN2 ( P: -- flag ) ( F: r1 r2 -- r1 r2 or r3 )
Examines the top two numbers on the fp stack and leaves a
Leaves numbers unchanged and true flag on the parameter
stack if both are valid. Leaves a false flag and the number
with the higher error code if one or both are invalid
numbers.

?NUMBER1 ( P: -- true )( F: r1 -- r1 ) or
( P: -- false )( F: r1 -- NA or ERR )
?NUMBER2 ( P: -- true )( F: r1 r2 -- r1 r2 )
( P: -- false )( F: r1 r2 -- NA or ERR )
?NUMBER3 ( P: -- true )( F: r1 r2 r3 -- r1 r2 r3)
( P: -- false )( F: r1 r2 r3 -- NA or ERR )
The above words check the top 1, 2, or 3 values on the
FP stack. If any are NA, a false flag is left, the input
arguments are dropped, and NA is returned on the FP stack.
If any are NAN's other than NA, strings, or ranges, a false
flag is returned, the input arguments are dropped, and ERR
is returned on the FP stack. Otherwise, the input arguments
are left on the stack and a true flag is returned, except
that [any ranges are replaced by the values of the cells in
their upper left corners and] any strings are replaced by 0.


?STRING1 ( P: -- true )( F: r1 -- r1 ) or
( P: -- false)( F: r1 -- NA or ERR )
?STRING2 ( P: -- true )( F: r1 r2 -- r1 r2 ) or
( P: -- false)( F: r1 r2 -- NA or ERR )
The above words check the top 1 or 2 values on the
FP stack. If any are NA, a false flag is left, the input
arguments are dropped, and NA is returned on the FP stack.
If any are NAN's other than NA or strings, or if any are
numbers, a false flag is returned, the input arguments are
dropped, and ERR is returned on the FP stack. Otherwise,
the input arguments are left on the stack and a true flag is
returned.


RADIANS ( -- )
This is a NOOP. Trig functions always take radian arguments.

FSIN ( F: r -- sin[r] )
The floating point sine function. There is no check made
for very large magnitude arguments.

FCOS ( F: r -- cos[r] )
The floating point cosine function. There is no check made
for very large arguments.

FTAN ( F: r -- tan[r] )
The trigonometric tangent function. There is no check made for
very large magnitude arguments.

FEXP ( F: r -- e^r )
The exponential function e^r .

FALN ( F: r -- e^r )
The inverse natural logarithm function. Identical to FEXP .

FALOG ( F: r -- 10^r )
The inverse common logarithm.

^^ ( F: r1 r2 -- r2^r2 )
F** ( F: r1 r2 -- r2^r2 )
Raise the second number on the f.p. stack to the power specified
at the top of the stack.

FATAN ( F: r -- arctan[r] )
The arctangent function. Return an angle whose tangent is the
input argument.

FATAN2 ( F: x y -- arctan[y/x] )
Return the angle whose tangent is y/x.

FASIN ( F: r -- arcsin[r] )
The arcsin function. Return an angle whose sine is the input
argument.

FACOS ( F: r -- arccos[r] )
The arccosine function. Return an angle whose cosine is the
input argument.

FLOATS ( -- )
FLOATING ( -- )
Sets floating point mode. Allows the user to enter floating point
numbers as simple numeric strings with imbedded decimal points.
The exponential notation is optional.

DOUBLE ( -- )
Clears floating pt mode. Restores the usual Forth convention that
a decimal point attached to a number causes the number to be
treated as a double number.

REAL+ ( adr1 -- adr2 )
Add the size of a floating-point number, specified in address units
to adr1, giving adr2.

REALS ( n1 -- n2 )
n2 is the size, in address units, of n1 floating point numbers.



 December 8, 2017  Add comments

Leave a Reply