2 Contributed by Paolo Bonzini
4 Copyright 2002-2003, 2007, 2009-2011 Free Software Foundation, Inc.
6 This file is part of gnulib.
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
28 static const long double C[] = {
29 /* Chebyshev polynom coeficients for (exp(x)-1)/x */
37 1.66666666666666666666666666666666683E-01L,
38 4.16666666666666666666654902320001674E-02L,
39 8.33333333333333333333314659767198461E-03L,
40 1.38888888889899438565058018857254025E-03L,
41 1.98412698413981650382436541785404286E-04L,
43 /* Smallest integer x for which e^x overflows. */
45 11356.523406294143949491931077970765L,
47 /* Largest integer x for which e^x underflows. */
49 -11433.4627433362978788372438434526231L,
51 /* very small number */
57 5.94865747678615882542879663314003565E+4931L};
62 /* Check for usual case. */
63 if (x < himark && x > lomark)
68 long double result = 1.0;
70 /* Compute an integer power of e with a granularity of 0.125. */
71 exponent = (int) floorl (x * 8.0L);
82 t = 0.8824969025845954028648921432290507362220L; /* e^-0.25 */
86 t = 1.1331484530668263168290072278117938725655L; /* e^0.25 */
99 /* Approximate (e^x - 1)/x, using a seventh-degree polynomial,
100 with maximum error in [-2^-16-2^-53,2^-16+2^-53]
101 less than 4.8e-39. */
102 x22 = x + x*x*(P1+x*(P2+x*(P3+x*(P4+x*(P5+x*P6)))));
104 return result + result * x22;
106 /* Exceptional cases: */
110 /* e^-inf == 0, with no error. */
117 /* Return x, if x is a NaN or Inf; or overflow, otherwise. */
125 printf ("%.16Lg\n", expl (1.0L));
126 printf ("%.16Lg\n", expl (-1.0L));
127 printf ("%.16Lg\n", expl (2.0L));
128 printf ("%.16Lg\n", expl (4.0L));
129 printf ("%.16Lg\n", expl (-2.0L));
130 printf ("%.16Lg\n", expl (-4.0L));
131 printf ("%.16Lg\n", expl (0.0625L));
132 printf ("%.16Lg\n", expl (0.3L));
133 printf ("%.16Lg\n", expl (0.6L));