2001-03-12 00:04:52 +00:00
|
|
|
/*
|
|
|
|
* IBM Accurate Mathematical Library
|
2002-07-06 06:36:39 +00:00
|
|
|
* written by International Business Machines Corp.
|
2016-01-04 16:05:18 +00:00
|
|
|
* Copyright (C) 2001-2016 Free Software Foundation, Inc.
|
2001-03-12 00:04:52 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
2002-08-26 22:40:48 +00:00
|
|
|
* the Free Software Foundation; either version 2.1 of the License, or
|
2001-03-12 00:04:52 +00:00
|
|
|
* (at your option) any later version.
|
2001-03-12 07:57:09 +00:00
|
|
|
*
|
2001-03-12 00:04:52 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2002-08-20 21:51:55 +00:00
|
|
|
* GNU Lesser General Public License for more details.
|
2001-03-12 00:04:52 +00:00
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
2012-02-09 23:18:22 +00:00
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
2001-03-12 00:04:52 +00:00
|
|
|
*/
|
|
|
|
/**************************************************************************/
|
|
|
|
/* MODULE_NAME:slowexp.c */
|
|
|
|
/* */
|
2001-03-12 07:57:09 +00:00
|
|
|
/* FUNCTION:slowexp */
|
2001-03-12 00:04:52 +00:00
|
|
|
/* */
|
|
|
|
/* FILES NEEDED:mpa.h */
|
|
|
|
/* mpa.c mpexp.c */
|
|
|
|
/* */
|
|
|
|
/*Converting from double precision to Multi-precision and calculating */
|
|
|
|
/* e^x */
|
|
|
|
/**************************************************************************/
|
2012-03-09 19:29:16 +00:00
|
|
|
#include <math_private.h>
|
2001-03-12 00:04:52 +00:00
|
|
|
|
2013-10-11 17:07:53 +00:00
|
|
|
#include <stap-probe.h>
|
|
|
|
|
2013-03-07 07:55:02 +00:00
|
|
|
#ifndef USE_LONG_DOUBLE_FOR_MP
|
|
|
|
# include "mpa.h"
|
|
|
|
void __mpexp (mp_no *x, mp_no *y, int p);
|
|
|
|
#endif
|
|
|
|
|
2011-10-25 04:56:33 +00:00
|
|
|
#ifndef SECTION
|
|
|
|
# define SECTION
|
|
|
|
#endif
|
|
|
|
|
2001-03-12 00:04:52 +00:00
|
|
|
/*Converting from double precision to Multi-precision and calculating e^x */
|
2011-10-25 04:56:33 +00:00
|
|
|
double
|
|
|
|
SECTION
|
2013-02-25 10:43:35 +00:00
|
|
|
__slowexp (double x)
|
|
|
|
{
|
2013-03-07 07:55:02 +00:00
|
|
|
#ifndef USE_LONG_DOUBLE_FOR_MP
|
2013-02-25 10:43:35 +00:00
|
|
|
double w, z, res, eps = 3.0e-26;
|
2001-03-12 07:57:09 +00:00
|
|
|
int p;
|
2013-02-25 10:43:35 +00:00
|
|
|
mp_no mpx, mpy, mpz, mpw, mpeps, mpcor;
|
2001-03-12 07:57:09 +00:00
|
|
|
|
2013-02-25 10:43:35 +00:00
|
|
|
/* Use the multiple precision __MPEXP function to compute the exponential
|
|
|
|
First at 144 bits and if it is not accurate enough, at 768 bits. */
|
|
|
|
p = 6;
|
|
|
|
__dbl_mp (x, &mpx, p);
|
|
|
|
__mpexp (&mpx, &mpy, p);
|
|
|
|
__dbl_mp (eps, &mpeps, p);
|
|
|
|
__mul (&mpeps, &mpy, &mpcor, p);
|
|
|
|
__add (&mpy, &mpcor, &mpw, p);
|
|
|
|
__sub (&mpy, &mpcor, &mpz, p);
|
|
|
|
__mp_dbl (&mpw, &w, p);
|
|
|
|
__mp_dbl (&mpz, &z, p);
|
|
|
|
if (w == z)
|
2013-10-11 17:07:53 +00:00
|
|
|
{
|
|
|
|
/* Track how often we get to the slow exp code plus
|
|
|
|
its input/output values. */
|
|
|
|
LIBC_PROBE (slowexp_p6, 2, &x, &w);
|
|
|
|
return w;
|
|
|
|
}
|
2013-02-25 10:43:35 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
p = 32;
|
|
|
|
__dbl_mp (x, &mpx, p);
|
|
|
|
__mpexp (&mpx, &mpy, p);
|
|
|
|
__mp_dbl (&mpy, &res, p);
|
2013-10-11 17:07:53 +00:00
|
|
|
|
|
|
|
/* Track how often we get to the uber-slow exp code plus
|
|
|
|
its input/output values. */
|
|
|
|
LIBC_PROBE (slowexp_p32, 2, &x, &res);
|
2013-02-25 10:43:35 +00:00
|
|
|
return res;
|
|
|
|
}
|
2013-03-07 07:55:02 +00:00
|
|
|
#else
|
|
|
|
return (double) __ieee754_expl((long double)x);
|
|
|
|
#endif
|
2001-03-12 00:04:52 +00:00
|
|
|
}
|