Floating-Point Words
No separate floating-point stack. A single precision floating-point number is one cell. The 32-bit base-2 format is officially referred to as binary32
IEEE 754-2008
.
Bare FPU Words (Without C Math Library)
f+ ( r1 r2 -- r3 ) Add r1 to r2 giving the sum r3
f- ( r1 r2 -- r3 ) Subtract r2 from r1, giving r3
f* ( r1 r2 -- r3 ) Multiply r1 by r2 giving r3
f/ ( r1 r2 -- r3 ) Divide r1 by r2, giving the quotient r3
fsqrt ( r1 -- r2 ) r2 is the square root of r1
fabs ( r1 -- r2 ) r2 is the absolute value of r1
fnegate ( r1 -- r2 ) r2 is the negation of r1
fround ( r1 -- r2 ) round r1 to an integral value using the "round to nearest" rule, giving r2
fflags@ ( -- u ) get the current value of the Floating Point Status/Control register FPSCR
fflags! ( u -- ) assign the given value to the Floating Point Status/Control register FPSCR
f0= ( r -- ? ) flag is true if r is equal to zero
f0< ( r -- ? ) flag is true if r is less than zero
f< ( r1 r2 -- ? ) flag is true if r1 is less than r2
f~ ( r1 r2 r3 -- ? ) If r3 is positive, flag is true if the absolute value of (r1 minus r2) is less than r3
If r3 is zero, flag is true if the implementation-dependent encoding of r1 and r2 are exactly identical
(positive and negative zero are unequal if they have distinct encodings).
If r3 is negative, flag is true if the absolute value of (r1 minus r2) is less than the absolute value
of r3 times the sum of the absolute values of r1 and r2.
f>s ( r -- n ) n is the single-cell signed-integer equivalent of the integer portion of r
s>f ( n -- r ) r is the floating-point equivalent of the single-cell value n
f>fx ( r -- x ) x is the fixed-point equivalent of the floating-point r
fx>f ( x -- r ) r is the floating-point equivalent of the fixed-point x
pi ( -- r ) r is pi, approx. 3.14159274101257324
e ( -- r ) r is e, approx. 2.7182818
fnumber (a # -- r u ) convert the specified string by a and # to float r, on success u is 1, otherwise 0
>float (a # -- r ? ) convert the specified string by a and # to float r, on success flag is true (more robust)
f. ( r -- ) display, with a trailing space, the floating-point number r in fixed-point notation
fe. ( r -- ) display, with a trailing space, the floating-point number r in engineering notation
fs. ( r -- ) display, with a trailing space, the floating-point number r in scientific notation
precision ( -- u ) return the number of significant digits currently used by F., FE., or FS. as u
set-precision ( u -- ) set the number of significant digits currently used by F., FE., or FS. to u
Words Using C Math Library
fsin ( r1 -- r2 ) r2 is the sine of the radian angle r1
Fixed-Point Words
Fixed-point
numbers (s31.32) are stored ( n-comma n-whole ) and can be handled like signed double numbers.
Because of the name conflict with the floating-point words I changed the names of the fixed-point word and use for fixed-point words x instead of f.
All angles are in degrees.
d+ ( x1 x2 -- x3 ) add x1 to x2 giving the sum x3
d- ( x1 x2 -- x3 ) subtract x2 from x1, giving x3
x* ( x1 x2 -- x3 ) multiply x1 by x2 giving x3
x/ ( x1 x2 -- x3 ) divide x1 by x2, giving the quotient x3
x. ( x -- ) display, with a trailing space, the fixed-point number x
x.n ( x n -- ) print a fixed-point number x with n fractional digits (truncated)
x#S ( n1 -- n2 ) Adds 32 comma-digits to number output
x# ( n1 -- n2 ) Adds one comma-digit to number output
sqrt ( x1 -- x2 ) x2 is the square root of x1
sin
cos
tan
asin
acos
atan
log2
log10
ln
pow2
pow10
exp
floor
deg2rad ( deg -- rad )
rad2deg ( rad -- deg )
pi
pi/2
pi/4
+inf
-inf
fixpt-mat-lib.fs