chiark / gitweb /
eglibc (2.11.3-4+deb6u3) squeeze-lts; urgency=medium
[eglibc.git] / sysdeps / powerpc / powerpc64 / power4 / fpu / slowexp.c
1 /*
2  * IBM Accurate Mathematical Library
3  * written by International Business Machines Corp.
4  * Copyright (C) 2001, 2007 Free Software Foundation
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
8  * the Free Software Foundation; either version 2.1 of the License, or
9  * (at your option) any later version.
10  *
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
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19  */
20 /**************************************************************************/
21 /*  MODULE_NAME:slowexp.c                                                 */
22 /*                                                                        */
23 /*  FUNCTION:slowexp                                                      */
24 /*                                                                        */
25 /*  FILES NEEDED:mpa.h                                                    */
26 /*               mpa.c mpexp.c                                            */
27 /*                                                                        */
28 /*Converting from double precision to Multi-precision and calculating     */
29 /* e^x                                                                    */
30 /**************************************************************************/
31 #include "math_private.h"
32
33 #ifdef NO_LONG_DOUBLE
34 #include "mpa.h"
35 void __mpexp(mp_no *x, mp_no *y, int p);
36 #endif
37
38 /*Converting from double precision to Multi-precision and calculating  e^x */
39 double __slowexp(double x) {
40 #ifdef NO_LONG_DOUBLE
41   double w,z,res,eps=3.0e-26;
42   int p;
43   mp_no mpx, mpy, mpz,mpw,mpeps,mpcor;
44
45   p=6;
46   __dbl_mp(x,&mpx,p); /* Convert a double precision number  x               */
47                     /* into a multiple precision number mpx with prec. p. */
48   __mpexp(&mpx, &mpy, p); /* Multi-Precision exponential function */
49   __dbl_mp(eps,&mpeps,p);
50   __mul(&mpeps,&mpy,&mpcor,p);
51   __add(&mpy,&mpcor,&mpw,p);
52   __sub(&mpy,&mpcor,&mpz,p);
53   __mp_dbl(&mpw, &w, p);
54   __mp_dbl(&mpz, &z, p);
55   if (w == z) return w;
56   else  {                   /* if calculating is not exactly   */
57     p = 32;
58     __dbl_mp(x,&mpx,p);
59     __mpexp(&mpx, &mpy, p);
60     __mp_dbl(&mpy, &res, p);
61     return res;
62   }
63 #else
64   return (double) __ieee754_expl((long double)x);
65 #endif
66 }