# HG changeset patch # User Bruno Haible # Date 1331031837 -3600 # Node ID 5626e55f7f0b850f32fe3b271d86ac37c77f8741 # Parent 7bea32ad55608a30c58b5bf0b503db9b8d364a56 expl: Simplify computation. * lib/expl.c (expl): Simplify computation of exp_y. Fix comment. diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2012-03-06 Bruno Haible + + expl: Simplify computation. + * lib/expl.c (expl): Simplify computation of exp_y. Fix comment. + 2012-03-05 Bruno Haible exp* tests: More tests. diff --git a/lib/expl.c b/lib/expl.c --- a/lib/expl.c +++ b/lib/expl.c @@ -84,7 +84,7 @@ where sinh(y) is computed through the power series: sinh(y) = y + y^3/3! + y^5/5! + ... and cosh(y) is computed as hypot(1, sinh(y)), - - or as exp(2*z) = (1 + tanh(z))^2 / (1 - tanh(z)^2) + - or as exp(2*z) = (1 + tanh(z)) / (1 - tanh(z)) where z = y/2 and tanh(z) is computed through its power series: tanh(z) = z @@ -135,21 +135,19 @@ * z2 + TANH_COEFF_1) * z; - long double exp_y = - ((1.0L + tanh_z) * (1.0L + tanh_z)) / (1.0L - tanh_z * tanh_z); + long double exp_y = (1.0L + tanh_z) / (1.0L - tanh_z); int n = (int) roundl (nm * (1.0L / 256.0L)); int m = (int) nm - 256 * n; /* expl_table[i] = exp((i - 128) * log(2)/256). Computed in GNU clisp through - (progn (setf (long-float-digits) 128) (setq a 0L0) (setf (long-float-digits) 256) (dotimes (i 257) (format t " ~D,~%" - (float (exp (* (/ (- i 128) 256) (log 2L0))) a)))) */ + (float (exp (* (/ (- i 128) 256) (log 2L0))) a))) */ static const long double expl_table[257] = { 0.707106781186547524400844362104849039284L,