[Seed7-users] Seed7 math functions expm1 and lnp1
Interpreter and compiler for the Seed7 programming language.
Brought to you by:
thomas_mertes
From: SJain <zz...@ym...> - 2021-08-30 11:36:31
|
1. If float accuracy is only double precision (64 bits) why are PI and E specified to so many more digits in math.s7i? 2. There is loss of significant digits of precision when computing a) e^x -1 from exp(x), b) ln(1+x) from ln(x) and c) sinh(x) from exp(x), when x is small, x<<1. This occurs because for x<<1, e^x is close to 1 and e^x -1 is taking difference of two almost equal numbers which are both near unity while the difference is much less than unity. Likwise ln(1+x) and sinh(x) cannot be accurately computed from ln(x) and exp(x) for x<<1. In x87 FPU, C and ANSI Forth, the functions expm1 and lnp1 (log1p in C math library) are provided for x<<1 which allow accurate computation for entire range of x. It may be noted that given exp, ln, expm1 and lnp1 functions one can compute all the hyperbolic functions and their inverses over the entire range of x. I request that expm1 and lnp1 functions be added to math.s7i library and that definition of sinh(x) be suitably amended for small x. Sanjay Jain Agra, India |