]>
Commit | Line | Data |
---|---|---|
e4d82761 UD |
1 | /* |
2 | * IBM Accurate Mathematical Library | |
aeb25823 | 3 | * written by International Business Machines Corp. |
d4697bc9 | 4 | * Copyright (C) 2001-2014 Free Software Foundation, Inc. |
e4d82761 UD |
5 | * |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU Lesser General Public License as published by | |
cc7375ce | 8 | * the Free Software Foundation; either version 2.1 of the License, or |
e4d82761 | 9 | * (at your option) any later version. |
50944bca | 10 | * |
e4d82761 UD |
11 | * This program is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
c6c6dd48 | 14 | * GNU Lesser General Public License for more details. |
e4d82761 UD |
15 | * |
16 | * You should have received a copy of the GNU Lesser General Public License | |
59ba27a6 | 17 | * along with this program; if not, see <http://www.gnu.org/licenses/>. |
e4d82761 UD |
18 | */ |
19 | /**************************************************************************/ | |
20 | /* MODULE_NAME:slowexp.c */ | |
21 | /* */ | |
50944bca | 22 | /* FUNCTION:slowexp */ |
e4d82761 UD |
23 | /* */ |
24 | /* FILES NEEDED:mpa.h */ | |
25 | /* mpa.c mpexp.c */ | |
26 | /* */ | |
27 | /*Converting from double precision to Multi-precision and calculating */ | |
28 | /* e^x */ | |
29 | /**************************************************************************/ | |
1ed0291c | 30 | #include <math_private.h> |
e4d82761 | 31 | |
10e1cf6b SP |
32 | #include <stap-probe.h> |
33 | ||
ce544b5b SP |
34 | #ifndef USE_LONG_DOUBLE_FOR_MP |
35 | # include "mpa.h" | |
36 | void __mpexp (mp_no *x, mp_no *y, int p); | |
37 | #endif | |
38 | ||
31d3cc00 UD |
39 | #ifndef SECTION |
40 | # define SECTION | |
41 | #endif | |
42 | ||
e4d82761 | 43 | /*Converting from double precision to Multi-precision and calculating e^x */ |
31d3cc00 UD |
44 | double |
45 | SECTION | |
2f22a1e8 SP |
46 | __slowexp (double x) |
47 | { | |
ce544b5b | 48 | #ifndef USE_LONG_DOUBLE_FOR_MP |
2f22a1e8 | 49 | double w, z, res, eps = 3.0e-26; |
50944bca | 50 | int p; |
2f22a1e8 | 51 | mp_no mpx, mpy, mpz, mpw, mpeps, mpcor; |
50944bca | 52 | |
2f22a1e8 SP |
53 | /* Use the multiple precision __MPEXP function to compute the exponential |
54 | First at 144 bits and if it is not accurate enough, at 768 bits. */ | |
55 | p = 6; | |
56 | __dbl_mp (x, &mpx, p); | |
57 | __mpexp (&mpx, &mpy, p); | |
58 | __dbl_mp (eps, &mpeps, p); | |
59 | __mul (&mpeps, &mpy, &mpcor, p); | |
60 | __add (&mpy, &mpcor, &mpw, p); | |
61 | __sub (&mpy, &mpcor, &mpz, p); | |
62 | __mp_dbl (&mpw, &w, p); | |
63 | __mp_dbl (&mpz, &z, p); | |
64 | if (w == z) | |
10e1cf6b SP |
65 | { |
66 | /* Track how often we get to the slow exp code plus | |
67 | its input/output values. */ | |
68 | LIBC_PROBE (slowexp_p6, 2, &x, &w); | |
69 | return w; | |
70 | } | |
2f22a1e8 SP |
71 | else |
72 | { | |
73 | p = 32; | |
74 | __dbl_mp (x, &mpx, p); | |
75 | __mpexp (&mpx, &mpy, p); | |
76 | __mp_dbl (&mpy, &res, p); | |
10e1cf6b SP |
77 | |
78 | /* Track how often we get to the uber-slow exp code plus | |
79 | its input/output values. */ | |
80 | LIBC_PROBE (slowexp_p32, 2, &x, &res); | |
2f22a1e8 SP |
81 | return res; |
82 | } | |
ce544b5b SP |
83 | #else |
84 | return (double) __ieee754_expl((long double)x); | |
85 | #endif | |
e4d82761 | 86 | } |