NFFT  3.3.1
float.c
00001 /*
00002  * Copyright (c) 2002, 2016 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 #include "infft.h"
00020 
00021 R Y(float_property)(const float_property p)
00022 {
00023   const R base = FLT_RADIX;
00024   const R eps = EPSILON;
00025   const R t = MANT_DIG;
00026   const R emin = MIN_EXP;
00027   const R emax = MAX_EXP;
00028   const R prec = eps * base;
00029   static R rmin = K(1.0);
00030   static R rmax = K(1.0);
00031   const R rnd = FLTROUND;
00032   static R sfmin = K(-1.0);
00033   static short first = TRUE;
00034 
00035   if (first)
00036   {
00037     /* Compute rmin */
00038     {
00039       const INT n = 1 - MIN_EXP;
00040       INT i;
00041       for (i = 0; i < n; i++)
00042         rmin /= base;
00043     }
00044 
00045     /* Compute rmax */
00046     {
00047       INT i;
00048       rmax -= eps;
00049       for (i = 0; i < emax; i++)
00050         rmax *= base;
00051     }
00052 
00053     /* Compute sfmin */
00054     {
00055       R small = K(1.0) / rmax;
00056       sfmin = rmin;
00057       if (small >= sfmin)
00058         sfmin = small * (eps + K(1.0));
00059     }
00060 
00061     first = FALSE;
00062   }
00063 
00064   if (p == NFFT_EPSILON)
00065     return eps;
00066   else if (p == NFFT_SAFE__MIN)
00067     return sfmin;
00068   else if (p == NFFT_BASE)
00069     return base;
00070   else if (p == NFFT_PRECISION)
00071     return prec;
00072   else if (p == NFFT_MANT_DIG)
00073     return t;
00074   else if (p == NFFT_FLTROUND)
00075     return rnd;
00076   else if (p == NFFT_E_MIN)
00077     return  emin;
00078   else if (p == NFFT_R_MIN)
00079     return rmin;
00080   else if (p == NFFT_E_MAX)
00081     return emax;
00082   else if (p == NFFT_R_MAX)
00083     return rmax;
00084   else
00085     CK(0 /* cannot happen */);
00086 
00087   return K(-1.0);
00088 } /* dlamch_ */
00089 
00091 R Y(prod_real)(R *vec, INT d)
00092 {
00093   INT t;
00094   R prod;
00095 
00096   prod = K(1.0);
00097   for (t = 0; t < d; t++)
00098     prod *= vec[t];
00099 
00100   return prod;
00101 }