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 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 "mpa.h"
00032 #include "math_private.h"
00033 
00034 void __mpexp(mp_no *x, mp_no *y, int p);
00035 
00036 /*Converting from double precision to Multi-precision and calculating  e^x */
00037 double __slowexp(double x) {
00038   double w,z,res,eps=3.0e-26;
00039 #if 0
00040   double y;
00041 #endif
00042   int p;
00043 #if 0
00044   int orig,i;
00045 #endif
00046   mp_no mpx, mpy, mpz,mpw,mpeps,mpcor;
00047 
00048   p=6;
00049   __dbl_mp(x,&mpx,p); /* Convert a double precision number  x               */
00050                     /* into a multiple precision number mpx with prec. p. */
00051   __mpexp(&mpx, &mpy, p); /* Multi-Precision exponential function */
00052   __dbl_mp(eps,&mpeps,p);
00053   __mul(&mpeps,&mpy,&mpcor,p);
00054   __add(&mpy,&mpcor,&mpw,p);
00055   __sub(&mpy,&mpcor,&mpz,p);
00056   __mp_dbl(&mpw, &w, p);
00057   __mp_dbl(&mpz, &z, p);
00058   if (w == z) return w;
00059   else  {                   /* if calculating is not exactly   */
00060     p = 32;
00061     __dbl_mp(x,&mpx,p);
00062     __mpexp(&mpx, &mpy, p);
00063     __mp_dbl(&mpy, &res, p);
00064     return res;
00065   }
00066 }