home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / PROG / MISC / FPC355_2.ZIP / SMITH.ZIP / SFLOAT3.HLP < prev    next >
Encoding:
Text File  |  1988-11-02  |  15.9 KB  |  389 lines

  1. \ SFLOAT3    Third part of Software Floating-Point Package.
  2. \
  3. \               (c) Copyright 1988 by Robert L. Smith
  4. \                       2300 St Francis Dr.
  5. \                       Palo Alto, CA 94303
  6. \                          (415)856-9321
  7. \
  8. \       Permission is granted to use this package or its derivatives for
  9. \       private use.  For permission to use it in programs or packages
  10. \       sold for profit, please contact the author.
  11. \
  12.  
  13. 1GEXPTAB                        \ HIDDEN
  14.         Table of (1 - e**(k/16))  for k <= 0
  15.         Table of (e**(k/16) - 1)  for k >= 0
  16.  
  17. GEXPTAB   ( -- addr )           \ HIDDEN
  18.         Points to center of 1GEXPTAB.
  19.  
  20. Y**2                            \ HIDDEN
  21.         Label for code subroutine for squaring the argument in (BX,CX).
  22.  
  23. FRACT*                          \ HIDDEN
  24.         Label for code subroutine to multiply two 32 bit floating point
  25.         fractions.
  26.  
  27. GEXP1-                          \ HIDDEN
  28.         Auxiliary function for exp(x) -1.
  29.  
  30. GEXP1   ( F: r1 -- r2 )         \ HIDDEN
  31.         Auxilliary function for exp(x) for small arguments x < 2^-4
  32.  
  33. FNORMALIZE   ( F: ur1 -- r2 )
  34.         Normalize the unnormalized floating point number at the top of the
  35.         stack.
  36.  
  37. >INTFRACT   ( F: r1 -- r2 ; -- int )
  38.         Convert a floating point number into an integer and a real number
  39.         fractional part.  Note that r2 may not be normalized.
  40.  
  41. FLOOR   ( F: r -- ; -- n )
  42.         Convert the floating point number to the largest integer less
  43.         than or equal to the floating point number.
  44.  
  45. CEILING   ( F: r -- ; -- n )
  46.         Convert the floating point number to the smallest integer not
  47.         less than the floating point number.
  48.  
  49. GEXPTAB@   ( F: -- r ; n -- )           \ HIDDEN
  50.         Fetch a floating point number from the EXPTAB indexed by the
  51.         integer at the top of the stack.
  52.  
  53. AUX-    ( F: r1  -- r2 ; n -- )         \ HIDDEN
  54.         Auxilliary tables for calculating the exponential function.
  55.         Auxiliary function used with FEXP
  56.  
  57. AUX+    ( F: r1 -- r2 ; n -- )          \ HIDDEN
  58.         Auxiliary function used with FEXP
  59.  
  60. GEXP0   ( F: r1 -- r2 ; -- n )          \ HIDDEN
  61.         Auxiliary function used with FEXP
  62.  
  63. GEXPLN2   ( F: r1 -- r2 ; -- n )        \ HIDDEN
  64.         Auxiliary function used with FEXP
  65.  
  66. FEXP    ( F: r1 -- r2 )
  67.         Floating point exponential function  e^x
  68.  
  69. FALN    ( F: r1 -- r2 )                 \ FVG Required
  70.         Alternative name for the exponential function.  This is the name
  71.         specified in the FVG Standard Floating Point Extension.
  72.  
  73. F**     ( F: r1 +r2 -- r3 )              \ FVG Required
  74.         Leave the value of r1 raised to the power +r2.  Note that +r2 must
  75.         be non-negative, even if it converts exactly to an integer.
  76.  
  77. FALOG   ( F: r1 -- r2 )                 \ FVG Required
  78.         Take the inverse log of r1, i.e., raise 10 to the power of r1.
  79.  
  80. F2**    ( F: -- r ; n -- )             \ HIDDEN
  81.         Return a floating point value of 2 raised to the specified power.
  82.  
  83. F2**N-1   ( F: -- r ; n -- )            \ HIDDEN
  84.         Return a floating point number of 1 less than 2 raised to the
  85.         specified power.
  86.  
  87. FEXP-1    ( F: r1 -- r2 )  \ ( e**x - 1 )       \ HIDDEN
  88.         (e^x) - 1.
  89.  
  90. FSINH1   ( F: r1 -- r2 )                \ HIDDEN
  91.         Hyperbolic sin of a positive argument.
  92.  
  93. FSINH    ( F: r1 -- r2 )                \ FVG Optional
  94.         Hyberbolic sin function.
  95.  
  96. FCOSH   ( F: r1 -- r2 )                 \ FVG Optional
  97.         Hyperbolic cosine function.
  98.  
  99. FTANH1   ( F: r1 -- r2 )                \ HIDDEN
  100.         Hyperbolic tangent function of a positive argument.
  101.  
  102. FTANH   ( F: r1 -- r2 )                 \ FVG Optional
  103.         Hyperbolic tangent function.
  104.  
  105. F1.0E10  ( F: -- r )
  106.         Return a floating point constant of 10^10 .
  107.  
  108. F0.5    ( F: -- r )
  109.         Return a floating point constant of value 0.5 .
  110.  
  111. T#      ( t1 -- t2 )
  112.         Convert the least significant digit of the triple number t1 to
  113.         an ASCII character and put it in the numeric output buffer.  The
  114.         remaining value of the number replaces t1 on the stack.
  115.  
  116. TDUP0=   ( t -- t flag )
  117.         Push a flag of -1 on the stack if the triple number t is zero.
  118.         Otherwise push a value of 0.  The triple number is left unchanged.
  119.  
  120. FPARTS  ( F: r -- ; t sign exp )
  121.         Convert a floating point number to a triple precision integer, the
  122.         sign of the number, and a power of ten.
  123.  
  124. (E.)   ( F: r -- ; -- addr cnt )
  125.         Convert a floating point number to an address and count suitable
  126.         to be typed.  The output is in exponential format.
  127.  
  128. E.   ( F: r -- )                        \ FVG Required
  129.         Print a floating point number in exponential (power of ten) format.
  130.  
  131. E.R     ( F: r -- ; n1 n2 )             \ FVG Optional
  132.         Display the floating point number r on the currently selected
  133.         output device in exponential form with n1 digits to the right of
  134.         the decimal point, right justified in a field of width n2.
  135.  
  136. F#PLACES   ( -- n )                     \ FVG Optional
  137.         A constant leaving the maximum number of significant digits when a
  138.         real number is converted to its decimal ASCII equivalent for
  139.         display.
  140.  
  141. PLACES   ( n -- )                       \ FVG Required
  142.         Set the default number of digits that will be printed to the right
  143.         of the decimal point by the F. operator.  The argument will be
  144.         limited to the range 0 to 10.  Default value is 10.
  145.  
  146. (F.FRACT)   ( F: r -- #pl )             \ HIDDEN
  147.         An auxilliary function for F. and F.R to convert the digits to
  148.         the right of the decimal point in a form suitable for display.
  149.  
  150. (F.INT1)     ( F: r -- ; sign -- addr cnt )     \ HIDDEN
  151.         An auxilliary function for F.R .
  152.  
  153. HOLDBL   ( n -- )               \ HIDDEN
  154.         An auxilliary function to a spaces to the output string for
  155.         F.R .
  156.  
  157. (F.INT2)                        \ HIDDEN
  158.         An auxilliary function for use with F.R
  159.  
  160. (F.INTR)                        \ HIDDEN
  161.         Another auxilliary function for F.R
  162.  
  163. (F.1)    ( F: r1 -- r2 r3 ; #pl -- sign flag )
  164.         An auxilliary function for use with F. and F.R for printing the
  165.         fractional part of a floating point number.
  166.  
  167. F.      ( F: r -- )             \ FVG Required
  168.         Display the floating point number on the currently selected output
  169.         device in fixed-point form; i.e., the location of the decimal point
  170.         is adjusted so that no exponent need be displayed.  The number of
  171.         digits to the right of the decimal point specified by the most
  172.         recent execution of the word PLACES are printed to the right of the
  173.         decimal point.  A trailing blank follows.  For example, 4 PLACES
  174.         1.2345E02 F. will display as 123.4500b (where the "b" denotes an
  175.         ASCII blank).  If the number of digits to the left of the decimal
  176.         point is greater than 14, the error routine is called.
  177.  
  178. F.R   ( F: r -- ; n1 n2 )               \ FVG Optional
  179.         Display r on the currently selected output device in fixed point
  180.         form with n1 digits to the right of the decimal place, right
  181.         justified in a field of width n2.  If the number cannot be
  182.         represented within the given field width, the error routine is
  183.         called and the value is printed in exponent form.  For example,
  184.         1.2345e2 4 12 F.R will display as  bbbb123.4500 (where each "b"
  185.         character denotes an ASCII blank).
  186.  
  187. ?FSTACK   ( F: -- )
  188.         Check the floating point stack for overflow or underflow.  Display
  189.         an error message if appropriate.
  190.  
  191. .FS    ( F: -- )
  192.         Display the number of items on the floating point stack, and
  193.         display the top four numbers in exponent form.  If the stack is
  194.         less than 4 deep, display the actual number present.  The floating
  195.         point stack is left unchanged by this operation.
  196.  
  197. UNPACK   ( F: r -- ; -- d n )           \ FVG Optional
  198.         Convert a floating point number to a double precision integer amd
  199.         a power of 10.
  200.  
  201. FASINH   ( F: r1 -- r2 )                \ FVG Optional
  202.         Inverse hyperbolic sin function.
  203.  
  204. FACOSH   ( F: r1 -- r2 )                \ FVG Optional
  205.         Inverse hyperbolic cosine function.
  206.  
  207. FATANH   ( F: r1 -- r2 )                \ FVG Optional
  208.         Inverse hyperbolic tangent function.
  209.  
  210. UMT*   ( ut1 n -- ut2 )
  211.         Multiply a triple number by a single.
  212.  
  213. TS+   ( ut1 n -- ut2 )
  214.         Add a single precision number to a triple.
  215.  
  216. TCONVERT   ( ut1 adr1 -- ut2 adr2 )
  217.         Similiar to CONVERT.  Fetches convertable digits from the specified
  218.         address and converts the digits according to BASE until a non-digit
  219.         is encountered.  addr2 points to the unconvertable character.
  220.  
  221. TFLOAT   ( F: -- r ; ut -- )
  222.         Float a triple precision unsigned number.
  223.  
  224. VARIABLE FPT  0 FPT !
  225.  
  226. FLTS    ( -- addr )
  227.         A variable containing a flag.  If the flag is non-zero, numbers which
  228.         have an imbedded decimal point or comma are treated as floating point
  229.         values.  Otherwise, the numbers are treated as double numbers.
  230.  
  231. FLOATS  ( -- )
  232.         Set the flag FLTS .  Allows floating point numbers to be input using
  233.         imbedded decimal points and optional exponent fields.  For example:
  234.  
  235.                 FLOATS    1.234   -5.4
  236.  
  237.         will produce two floating point numbers.  Note, however, that a
  238.         single precision integer, such as 7 , will remain a single
  239.         precision integer, and a double number with a terminating decimal
  240.         point, such as 1234. , will remain a double number.
  241.  
  242. DOUBLES   ( -- )
  243.         Clear the FLTS flag so that the usual rules for double numbers applies.
  244.  
  245. PACK    ( F: -- r ; d n -- )            \ FVG Optional
  246.         Convert a double integer and a power of 10 to a floating point
  247.         number.
  248.  
  249. -NUMBER   ( adr1 -- adr2 flag )
  250.         Fetch next charcter from string at adr1.  If character is an ASCII -
  251.         (minus) sign, return the incremented address and a flag of -1.  If
  252.         the character is not an ASCII "-", don't increment the address, and
  253.         return a flag of 0.
  254.  
  255. 1FNUMBER   ( F: -- r ; ut adr --  -1 )  \ or  ( ut adr -- 0 ) if not convertable.
  256.         Attempt to convert the string specified by adr to a floating point
  257.         number.  If the result is successful, return the number and a -1 flag
  258.         on the stack.  If the attempt fails, return a zero on the stack.
  259.         Note that  ut  is an unsigned triple precision number.
  260.  
  261. (FNUMBER?)   ( F: -- r ; adr --  -1) \ (adr -- d 1 ) \ ( adr -- 0 )
  262.         Attempt to convert the string at adr into either a floating point
  263.         number or a double precision number, and return a flag.  If the
  264.         conversion process failed, return a flag of 0.  If the string was
  265.         converted into a floating point number, return the number and a flag
  266.         of -1.  If the string was converted into a double integer, return the
  267.         value and a flag of 1.  The value of  FLTS  (set by  FLOATS  or
  268.         cleared by  DOUBLES ) determines if a numeric string with an
  269.         imbedded decimal point is a floating point number or a double
  270.         number.
  271.  
  272. FNUMBER   ( F: -- r ; adr -- -1 ) \ ( adr -- d 1 )
  273.         Convert the string at the specified address into a real or integer
  274.         number, with a flag of -1 or 1, respectively.  If the number cannot
  275.         be converted, print an error message.
  276.  
  277. F#   ( F: -- r )
  278.         Convert the string following F# into a floating point number.
  279.         This includes numbers with or without decimal points.  Thus
  280.         F# 34  yields the equivalent of 34X0 .  If SFLOAT is loaded, even
  281.         if in NOFLOATING mode, F# still converts the following number and
  282.         pushes it onto the floating point stack.
  283.  
  284. #?    ( number --- d 1 ) \ ( F: -- r ; number --- -1 )
  285.         If possible, convert the following word in the input stream into a
  286.         number.  If the string converts to a floating point number, the
  287.         flag is set to -1 .  If the string converts to an integer, the
  288.         flag is set to 1.  If the string cannot be converted, a standard
  289.         error message is sent.
  290.  
  291. (FLIT)  ( F: -- r )
  292.         An in-line function to pick up an in-line literal (three words)
  293.         and push onto the floating point stack.
  294.  
  295. FLITERAL    ( F: -- r )
  296.         Create an in-line literal.
  297.  
  298. FINTERP       ( -- )
  299.         A version of INTERPRET which recognizes floating point numbers.
  300.  
  301. (F])          ( -- )
  302.         A version of the compiler, ] , which recognizes floating point
  303.         number.
  304.  
  305. DEFER OLD-INTERP                \ HIDDEN
  306.         A deferred word to hold the previous Interpreter.
  307.  
  308. DEFER OLD-]                     \ HIDDEN
  309.         A deferred word to hold the previous Compiler.
  310.  
  311. OLD-?STACK                      \ HIDDEN
  312.         A deferred word to hold the previous function which checks the
  313.         stack.
  314.  
  315. FLOATING      ( -- )
  316.         Replace the current interpreter and compiler with the Floating
  317.         Point version.  This mostly affects the ability to enter floating
  318.         point numbers.
  319.  
  320. NOFLOATING    ( -- )
  321.         Restore the previous interpreter and compiler.
  322.  
  323. AUXTAN  ( F: r1 -- ur2 )   \ ur2 is tan(x) - x , |x| < 2**-4  \ HIDDEN
  324.         Auxilary tangent function.
  325.  
  326. TANTAB  ( -- addr )                     \ HIDDEN
  327.         Table of tan(i/16)  for i = 0 to 12.
  328.  
  329. GTAN0   ( F: r1 -- r2 r3 )              \ HIDDEN
  330.         The tangent is the ratio of r2 to r3.
  331.  
  332. GTAN1   ( F: r1 -- r2 r3 ; flag )       \ HIDDEN
  333.         Return the tangent of r1 as a ratio of numbers r2 and r3.  The
  334.         flag is non-zero if r1 is sufficiently large that the quadrant
  335.         cannot be determined.
  336.  
  337. GTAN2   ( F: r1 -- r2 r3 ; -- flag1 flag2 )     \ HIDDEN
  338.         Return the tangent of r1 as a ratio of numbers r2 and r3.  Flag1
  339.         is non-zero if r1 is sufficiently large that the quadrant cannot
  340.         be determined.  Flag2 is non-zero if r3 = 0.
  341.  
  342. FTAN    ( F: r1 -- r2 )                 \ FVG Required
  343.         The input is a floating point number in radians.  The output is
  344.         is the tangent of the number.  An error condition exists for
  345.         sufficiently large input values.
  346.  
  347. FSIN    ( F: r1 -- r2 )                 \ FVG Required
  348.         Returns the sine of the input number in radians.  Input and output
  349.         values are floating point numbers.  An error condition exists for
  350.         sufficiently large input values.
  351.  
  352. FCOS    ( F: r1 -- r2 )         \ FVG Required
  353.         Returns the cosine of the floating point argument in radians.  An
  354.         error condition exists for sufficiently large input arguments.
  355.  
  356. AUXATAN   ( F: r1 -- ur2 )      \ HIDDEN
  357.         Auxilliary arctangent function for small positive numbers in the
  358.         range 0 <= r1 < 2^-4 .
  359.  
  360. ATANTAB   ( -- addr )           \ HIDDEN
  361.         A table of arctan (k/16), for k = 0 to 16.
  362.  
  363. GATAN1   ( F: r1 -- r2 )        \ HIDDEN
  364.         Auxilliary arctangent function for 0 <= r1 <= 1.0
  365.  
  366. GATAN2   ( F: r1 -- r2 )        \ HIDDEN
  367.         Auxilliary arctangent function for positive arguments.
  368.  
  369. FATAN   ( F: r1 -- r2 )         \ FVG Required
  370.         Returns a floating point value equal to the arctangent of the
  371.         input argument.  The result is expressed in radians.
  372.  
  373. FASIN   ( F: r1 -- r2 )         \ FVG Required
  374.         Returns a floating point value equal to the arcsine of the input
  375.         argument.  The result is expressed in radians.  If the input
  376.         argument exceeds 1.0 in value, an error condition results.
  377.  
  378. FACOS   ( F: r1 -- r2 )         \ FVG Required
  379.         Returns a floating point value equal to the arccosine of the
  380.         input argument.  The result is expressed in radians.  If the
  381.         input argument exceeds 1.0 in value, an error condition results.
  382.  
  383. FTRIG0  ( F: r1 -- r2 )
  384.         Returns a floating point value equal to the square root of the
  385.         absolute value of (1.0 - (r1^2)).  This is a useful auxilliary
  386.         function suggested in APL.
  387.  
  388.  
  389.