Back to index

glibc  2.9
slowexp.c
Go to the documentation of this file.
00001 /*
00002  * IBM Accurate Mathematical Library
00003  * written by International Business Machines Corp.
00004  * Copyright (C) 2001, 2007 Free Software Foundation
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU Lesser General Public License as published by
00008  * the Free Software Foundation; either version 2.1 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00019  */
00020 /**************************************************************************/
00021 /*  MODULE_NAME:slowexp.c                                                 */
00022 /*                                                                        */
00023 /*  FUNCTION:slowexp                                                      */
00024 /*                                                                        */
00025 /*  FILES NEEDED:mpa.h                                                    */
00026 /*               mpa.c mpexp.c                                            */
00027 /*                                                                        */
00028 /*Converting from double precision to Multi-precision and calculating     */
00029 /* e^x                                                                    */
00030 /**************************************************************************/
00031 #include "math_private.h"
00032 
00033 #ifdef NO_LONG_DOUBLE
00034 #include "mpa.h"
00035 void __mpexp(mp_no *x, mp_no *y, int p);
00036 #endif
00037 
00038 /*Converting from double precision to Multi-precision and calculating  e^x */
00039 double __slowexp(double x) {
00040 #ifdef NO_LONG_DOUBLE
00041   double w,z,res,eps=3.0e-26;
00042   int p;
00043   mp_no mpx, mpy, mpz,mpw,mpeps,mpcor;
00044 
00045   p=6;
00046   __dbl_mp(x,&mpx,p); /* Convert a double precision number  x               */
00047                     /* into a multiple precision number mpx with prec. p. */
00048   __mpexp(&mpx, &mpy, p); /* Multi-Precision exponential function */
00049   __dbl_mp(eps,&mpeps,p);
00050   __mul(&mpeps,&mpy,&mpcor,p);
00051   __add(&mpy,&mpcor,&mpw,p);
00052   __sub(&mpy,&mpcor,&mpz,p);
00053   __mp_dbl(&mpw, &w, p);
00054   __mp_dbl(&mpz, &z, p);
00055   if (w == z) return w;
00056   else  {                   /* if calculating is not exactly   */
00057     p = 32;
00058     __dbl_mp(x,&mpx,p);
00059     __mpexp(&mpx, &mpy, p);
00060     __mp_dbl(&mpy, &res, p);
00061     return res;
00062   }
00063 #else
00064   return (double) __ieee754_expl((long double)x);
00065 #endif
00066 }