Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

/ray/src/lib/numerics/macheps.cc

Go to the documentation of this file.
00001 /*
00002  * lib/numerics/macheps.cc
00003  * 
00004  * Compute machine precision for numerics code. 
00005  * 
00006  * Copyright (c) 2003--2004 by Wolfgang Wieser ] wwieser (a) gmx <*> de [ 
00007  * 
00008  * This file may be distributed and/or modified under the terms of the 
00009  * GNU General Public License version 2 as published by the Free Software 
00010  * Foundation. (See COPYING.GPL for details.)
00011  * 
00012  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00013  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00014  * 
00015  */
00016 
00017 #include "num_math.h"
00018 
00019 
00020 namespace NUM
00021 {
00022 
00023 template<typename T>static volatile void _CME_add1(T x,volatile T *res);
00024 
00025 template<typename T>static volatile T _ComputeMachEps1()
00026 {
00027     volatile T e=1.0e-5,pe=e,e1;
00028     do {
00029         pe=e;
00030         e/=1.5;
00031         _CME_add1(e,&e1);
00032     } while(e1>1.0);
00033     //fprintf(stderr,"Computed macheps1=%g=pow(2,%.2f) (sizeof(T)=%u)\n",
00034     //  pe,log(pe)/log(2.0),sizeof(T));
00035     return(pe);
00036 }
00037 
00038 template<typename T>static volatile void _CME_add1(T x,volatile T *res)
00039 {
00040     *res=1.0+x;
00041 }
00042 
00043 // This computes the precision macheps...
00044 template<typename T>static T _ComputeMachEps1_Prec()
00045 {
00046     register T e=1.0e-5,pe=e;
00047     while(1.0+e>1.0)
00048     {  pe=e;  e/=1.5;  }
00049     //fprintf(stderr,"Computed macheps1_prec=%g\n",pe);
00050     return(pe);
00051 }
00052 
00053 
00054 // Initialize global data: 
00055 const FPConst<dbl> fpconst_dbl=
00056 {
00057     INIT_FIELD(macheps1) _ComputeMachEps1<dbl>(),
00058     INIT_FIELD(sqrt_macheps1) sqrt(_ComputeMachEps1<dbl>()),
00059     INIT_FIELD(macheps1_prec) _ComputeMachEps1_Prec<dbl>()
00060 };
00061 
00062 const FPConst<flt> fpconst_flt=
00063 {
00064     INIT_FIELD(macheps1) _ComputeMachEps1<flt>(),
00065     INIT_FIELD(sqrt_macheps1) sqrt(_ComputeMachEps1<flt>()),
00066     INIT_FIELD(macheps1_prec) _ComputeMachEps1_Prec<flt>()
00067 };
00068 
00069 }  // end of namespace NUM

Generated on Sat Feb 19 22:33:45 2005 for Ray by doxygen 1.3.5