NFFT Logo 3.2.2
float.c
00001 /*
00002  * Copyright (c) 2002, 2012 Jens Keiner, Stefan Kunis, Daniel Potts
00003  *
00004  * This program is free software; you can redistribute it and/or modify it under
00005  * the terms of the GNU General Public License as published by the Free Software
00006  * Foundation; either version 2 of the License, or (at your option) any later
00007  * version.
00008  *
00009  * This program is distributed in the hope that it will be useful, but WITHOUT
00010  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00011  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
00012  * details.
00013  *
00014  * You should have received a copy of the GNU General Public License along with
00015  * this program; if not, write to the Free Software Foundation, Inc., 51
00016  * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  */
00018 
00019 /* $Id: util.c 3483 2010-04-23 19:02:34Z keiner $ */
00020 
00021 #include "infft.h"
00022 
00023 R X(float_property)(const float_property p)
00024 {
00025   const R base = FLT_RADIX;
00026   const R eps = EPSILON;
00027   const R t = MANT_DIG;
00028   const R emin = MIN_EXP;
00029   const R emax = MAX_EXP;
00030   const R prec = eps * base;
00031   static R rmin = K(1.0);
00032   static R rmax = K(1.0);
00033   const R rnd = FLTROUND;
00034   static R sfmin = K(-1.0);
00035   static short first = TRUE;
00036 
00037   if (first)
00038   {
00039     /* Compute rmin */
00040     {
00041       const INT n = 1 - MIN_EXP;
00042       INT i;
00043       for (i = 0; i < n; i++)
00044         rmin /= base;
00045     }
00046 
00047     /* Compute rmax */
00048     {
00049       INT i;
00050       rmax -= eps;
00051       for (i = 0; i < emax; i++)
00052         rmax *= base;
00053     }
00054 
00055     /* Compute sfmin */
00056     {
00057       R small = K(1.0) / rmax;
00058       sfmin = rmin;
00059       if (small >= sfmin)
00060         sfmin = small * (eps + K(1.0));
00061     }
00062 
00063     first = FALSE;
00064   }
00065 
00066   if (p == NFFT_EPSILON)
00067     return eps;
00068   else if (p == NFFT_SAFE_MIN)
00069     return sfmin;
00070   else if (p == NFFT_BASE)
00071     return base;
00072   else if (p == NFFT_PRECISION)
00073     return prec;
00074   else if (p == NFFT_MANT_DIG)
00075     return t;
00076   else if (p == NFFT_FLTROUND)
00077     return rnd;
00078   else if (p == NFFT_E_MIN)
00079     return  emin;
00080   else if (p == NFFT_R_MIN)
00081     return rmin;
00082   else if (p == NFFT_E_MAX)
00083     return emax;
00084   else if (p == NFFT_R_MAX)
00085     return rmax;
00086   else
00087     CK(0 /* cannot happen */);
00088 
00089   return K(-1.0);
00090 } /* dlamch_ */

Generated on Fri Oct 12 2012 by Doxygen 1.8.0-20120409