Heidelberg Educational Numerics Library Version 0.24 (from 9 September 2011)

src/precision.hh

Go to the documentation of this file.
00001 // -*- tab-width: 4; indent-tabs-mode: nil -*-
00002 #ifndef HDNUM_PRECISION_HH
00003 #define HDNUM_PRECISION_HH
00004 
00009 namespace hdnum {
00010 
00011   // find largest eps such that 0.5 + eps > 0.5
00012   template<typename X>
00013   int precision (X& eps)
00014   {
00015         X x,large,largex,two;
00016         large = 0.5;
00017         two = 2.0;
00018         x = 0.5;
00019         largex = large+x;
00020         int i(0);
00021         while (largex>large)
00022           {
00023                 eps = x;
00024                 i = i+1;
00025                 //              std::cout << i << " " << std::scientific << std::showpoint 
00026                 //                << std::setprecision(15) << large+x << " " << x << std::endl;
00027                 x = x/two;
00028                 largex = large+x;
00029           }
00030         return i;
00031   } 
00032 
00033 } // namespace hdnum
00034 
00035 #endif