home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / forth / compiler / fpc / help / sfloat1.hlp < prev    next >
Encoding:
Text File  |  1988-11-02  |  10.5 KB  |  250 lines

  1. \ Software Floating Point Package for FORTH  -- Forward, sequential version.
  2. \          (c) Copyright 1988  by Robert L. Smith
  3. \                  2300 St. Francis Dr.
  4. \                  Palo Alto, CA 94303
  5. \
  6. \  Permission to use this package or its derivatives is granted for private
  7. \  use.  For permission to use in programs or packages sold for profit,
  8. \  please contact the author.
  9.  
  10. FPPACKAGE       A dummy word for ANEW to forget to.
  11.  
  12. F#BYTES  ( -- n )                       \ FVG Optional
  13.         The number of bytes in a floating point word.
  14.  
  15. FPSTAT   Holds error information        \ FVG Optional
  16.  
  17. FPSIZE   ( -- n )               \ HIDDEN
  18.         The maximum number of floating point variables in the floating
  19.         point stack.
  20.  
  21. FPSTACK                         \ HIDDEN
  22.         An array to hold the floating point stack.
  23.  
  24. FSP0    ( -- addr )
  25.         Returns the address of the base of the floating point stack.
  26.  
  27. FSP     ( -- addr )
  28.         Returns the address of a variable which points to the top of
  29.         the floating point stack.
  30.  
  31. FDEPTHB   ( -- n )
  32.         The depth of the floating point stack, in bytes.
  33.  
  34. FDEPTH   ( -- n )
  35.         The depth of the floating point stack in floating point words
  36.         (three words or six bytes).
  37.  
  38. FCLEAR    ( -- )
  39.         Empty the floating point stack.
  40.  
  41. AND!    ( n addr -- )
  42.         Performs a logical AND function with n and the contents at
  43.         addr, returning the result to addr .
  44.  
  45. OR!     ( n addr -- )
  46.         Performs a logical OR function with n and the contents at addr,
  47.         returning the result to addr.
  48.  
  49. FPOP    ( F: r -- ; -- d n )
  50.         Pops the return stack and pushes the same bit pattern onto the
  51.         parameter stack.  The double number is the fractional part, and
  52.         the single number is the combined sign and biased exponent.
  53.  
  54. FPUSH   ( F: -- r ; d n -- )
  55.         Removes three numbers from the parameter stack and pushes them
  56.         onto the floating point stack.
  57.  
  58. FPCOPY  ( F: r -- r ; -- d n )
  59.         Copy the contents of the floating point number at the top of the
  60.         floating point stack onto the parameter stack.  Equivalent to
  61.         FDUP FPOP .
  62.  
  63. FPFRACT  ( F: r -- r ; -- d )
  64.         Copy the fractional part of the floating point number at the top
  65.         of the floating point stack onto the parameter stack.
  66.  
  67. FPSEXP   ( F: r -- r ; -- n )
  68.         Copy the sign and exponent of the floating point number at the
  69.         top of the floating point stack onto the parameter stack.
  70.  
  71. 2/?     ( n1 -- n2 n3 )
  72.         n2 is n1 shifted right by 1, and n3 is the least significant bit
  73.         of n1.
  74.  
  75. .NAME   ( n1 -- )
  76.         Print the name of the word whose execution address is n1.
  77.  
  78. FPERR   ( F: r1 -- r2 ; n -- )          \ FVG Optional
  79.         A defered word to execute on a floating point error.
  80.  
  81. .FP.    ( -- )                  \ HIDDEN
  82.         Print the string "Floating Point".
  83.  
  84. (FPERR)  ( F: r1 -- r2 ; n -- ) \ HIDDEN
  85.         Default word to execute on a floating point error.
  86.  
  87. DENORM                          \ HIDDEN
  88.         A code-level subroutine to de-normalize a floating point number.
  89.         CX = count, BX = Hi, DX = LO, AX = Guard, Round, & Sticky.
  90.  
  91. F-     ( F: r1 r2 -- r3 )               \ FVG Required
  92.         Subtract the floating point number at the top of the stack from the
  93.         floating point number second on the stack.  Report overflow errors.
  94.  
  95. F\-    ( F: r1 r2 -- r3 )     \ Reverse subtraction
  96.         Subtract the floating point number second on the stack from the
  97.         floating point number at the top of the stack.  Report overflow
  98.         errors.
  99.  
  100. F+      ( F: r1 r2 -- r3 )              \ FVG Required
  101.         Add the two floating point numbers at the top of the stack.  The
  102.         result is placed back on the stack.  Report overflow errors.
  103.  
  104. F*    ( F: r1 r2 -- r3 )                \ FVG Required
  105.         Multiply the top two floating point numbers on the stack.  Report
  106.         overflow errors.
  107.  
  108. F/     ( F: r1 r2 -- r3 )               \ FVG Required
  109.         Divide the floating point number second on the stack by the floating
  110.         point number at the top of the stack.  Report overflow errors and
  111.         division by zero.
  112.  
  113. FSQRT   ( F: r1 -- r2 )                 \ FVG Required
  114.         Replace the floating point number at the top of the stack with its
  115.         square root.  Report an error if r1 is negative.
  116.  
  117. FDUP   ( F: r -- r r )                  \ FVG Required
  118.         Duplicate the floating point number at the top of the stack.
  119.  
  120. FDROP   ( F: r -- )                     \ FVG Required
  121.         Drop the top floating point number from the stack.
  122.  
  123. F2DROP   ( F: r1 r2 -- )
  124.         Drop the top two floating point numbers from the stack.
  125.  
  126. FNIP    ( F: r1 r2 -- r1 )
  127.         Remove the second floating point number from the stack.
  128.         Equivalent to FSWAP FDROP .
  129.  
  130. FOVER   ( F: r1 r2 -- r1 r2 r1 )        \ FVG Required
  131.         Push a copy of the floating point number second on the stack.
  132.  
  133. F2DUP   ( F: r1 r2 -- r1 r2 r1 r2 )
  134.         Push a copy of the top two elements on the floating point stack.
  135.  
  136. FSWAP   ( F: r1 r2 -- r2 r1 )           \ FVG Required
  137.         Interchange the top two floating point numbers on the stack.
  138.  
  139. FROT    ( F: r1 r2 r3 -- r2 r3 r1 )     \ FVG Required
  140.         Rotate the top three elements on the floating point stack, bringing
  141.         the third element to the top.
  142.  
  143. F-ROT   ( F: r1 r2 r3 -- r3 r1 r2 )
  144.         Reverse rotate the top three elements on the floating point stack,
  145.         putting the top element to the third position.
  146.  
  147. FPICK   ( F: rn rn-1 ... r0 -- rn rn-1 ... r0 rn ; n -- )
  148.         Using a zero referenced value of n , pick the n-th value from the
  149.         floating point stack and push it onto the floating point stack.
  150.         Thus  0 FPICK  is equivalent to FDUP .
  151.  
  152. FNSWAP   ( F: rn rn-1 ... r0 -- r0 rn-1 ... r1 rn ; n -- )
  153.         Exchange the floating point value at the n-th location on the
  154.         floating point stack with the floating point value at the top
  155.         of the floating point stack.  Thus  1 FNSWAP  is equivalent to
  156.         FSWAP .
  157.  
  158. F0<   ( F: r1 -- ; -- flag )            \ FVG Required
  159.         Test the floating point number at the top of the floating point
  160.         stack.  If the number is less than zero, push a -1 flag on the
  161.         parameter stack.  If the floating point number is greater than or
  162.         equal to zero, push a 0 flag on the parameter stack.  In either
  163.         case, drop the floating point number from the floating point
  164.         stack.
  165.  
  166. FDUP0<    ( F: r1 -- r1 ; -- flag )
  167.         Test the floating point number at the top of the floating point
  168.         stack.  Do not drop that number.  If the number is less than zero,
  169.         push a -1 flag on the parameter stack.  Otherwise, push a zero
  170.         flag.
  171.  
  172. F0>   ( F: r1 -- ; -- flag )
  173.         Test the floating point number at the top of the stack, then drop
  174.         the number.  If the number was greater than zero, push a -1 flag
  175.         on the parameter stack.  Otherwise push a zero.
  176.  
  177. F0=   ( F: r -- ; -- flag )             \ FVG Required
  178.         Test the floating point number at the top of the stack, then drop
  179.         it.  If the number is zero, push a -1 on the parameter stack.
  180.         The flag is set to 0 if the floating point number was not zero.
  181.  
  182. F2DUP0=   ( F: r1 r2 -- r1 r2 ; -- flag )
  183.         Compare the top two floating point numbers, but do not drop them.
  184.         If the two numbers are equal, push a flag of -1 onto the parameter
  185.         stack.  If the numbers are not equal, push a flag of 0.
  186.  
  187. F=   ( F: r1 r2 -- ; -- flag )          \ FVG Required
  188.         Compare the top two floating point numbers.  If the numbers are
  189.         equal, push a flag of -1 on the parameter stack.  If the two
  190.         numbers are not equal, push a zero.  In either case, drop the two
  191.         numbers from the floating point stack.
  192.  
  193. F2DUP>   ( F: r1 r2 -- ; -- flag )
  194.         Compare the top two floating point numbers, but do not pop them
  195.         from the stack.  If the number second on the stack is greater than
  196.         the top number, push a flag of -1 onto the parameter stack.
  197.         Otherwise, push a zero onto the parameter stack.
  198.  
  199. F2DUP<   ( F: r1 r2 -- ; -- flag )
  200.         Compare the top two floating point numbers, but do not pop them
  201.         from the stack.  If the number second on the stack is less than
  202.         the top number, push a flag of -1 onto the parameter stack.
  203.         Otherwise, push a zero onto the parameter stack.
  204.  
  205. F<   ( F: r1 r2 -- ; -- flag )          \ FVG Required
  206.         Compare the top two floating point numbers.  If the number second
  207.         on the floating point stack is less than the top number, push
  208.         a flag of -1 onto the parameter stack.  Otherwise push a 0 onto
  209.         the parameter stack.  In either case, the top two numbers on the
  210.         floating point stack are dropped.
  211.  
  212. F>   ( F: r1 r2 -- ; -- flag )
  213.         Compare the top two floating point numbers.  If the number second
  214.         on the floating point stack is greater than the top number, push
  215.         a flag of -1 onto the parameter stack.  Otherwise push a 0 onto
  216.         the parameter stack.  In either case, the top two numbers on the
  217.         floating point stack are dropped.
  218.  
  219. F<=   ( F: r1 r2 -- ; -- flag )
  220.         Compare the top two floating point numbers.  If the number second
  221.         on the floating point stack is less or equal to the top number,
  222.         push a flag of -1 onto the parameter stack.  Otherwise push a 0
  223.         onto the parameter stack.  In either case drop the top two numbers
  224.         from the floating point stack.
  225.  
  226. F>=   ( F: r1 r2 -- ; -- flag )
  227.         Compare the top two floating point numbers.  If the number second
  228.         on the floating point stack greater than or equal to the top
  229.         number, push a flag of -1 onto the parameter stack.  Otherwise
  230.         push a 0 onto the parameter stack.  In either case drop the top
  231.         two numbers from the floating point stack.
  232.  
  233. FMAX   ( F: r1 r2 -- r3 )
  234.         Replace the top two numbers on the floating point stack with the
  235.         greater of the two.
  236.  
  237. FMIN   ( F: r1 r2 -- r3 )               \ FVG Required
  238.         Replace the top two numbers on the floating point stack with the
  239.         smaller of the two.
  240.  
  241. FABS   ( F: r1 -- r2 )                  \ FVG Required
  242.         Replace the floating point number at the top of the floating point
  243.         stack with its absolute value.
  244.  
  245. FNEGATE   ( F: r1 -- r2 )               \ FVG Required
  246.         Negate the floating point number at the top of the floating point
  247.         stack.
  248.  
  249.  
  250.