12.6.2.1516 FEXPM1 f-e-x-p-m-one FLOATING EXT

( F: r1 -- r2 ) or ( r1 -- r2 )

Raise e to the power r1 and subtract one, giving r2.

See:

Rationale:

This function allows accurate computation when its arguments are close to zero, and provides a useful base for the standard exponential functions. Hyperbolic functions such as sinh(x) can be efficiently and accurately implemented by using FEXPM1; accuracy is lost in this function for small values of x if the word FEXP is used.

An important application of this word is in finance; say a loan is repaid at 15% per year; what is the daily rate? On a computer with single-precision (six decimal digit) accuracy:

  1. Using FLN and FEXP: FLN of 1.15 = 0.139762,
    divide by 365 = 3.82910E-4,
    form the exponent using FEXP = 1.00038, and
    subtract one (1) and convert to percentage = 0.038%.
Thus we only have two-digit accuracy.
  1. Using FLNP1 and FEXPM1: FLNP1 of 0.15 = 0.139762, (this is the same value as in the first example, although with the argument closer to zero it may not be so)
    divide by 365 = 3.82910E-4,
    form the exponent and subtract one (1) using FEXPM1 = 3.82983E-4, and
    convert to percentage = 0.0382983%.
This calculation method allows the hyperbolic functions to be computed with six-digit accuracy. For example, sinh can be defined as:

: FSINH ( r1 -- r2 )
   FEXPM1 FDUP FDUP 1.0E0 F+ F/ F+ 2.0E0 F/ ;

ContributeContributions