realroot_doc 0.1.1
|
00001 /******************************************************************** 00002 * This file is part of the source code of the realroot library. 00003 * Author(s): J.P. Pavone, GALAAD, INRIA 00004 * $Id: epsilon.H,v 1.1 2005/07/11 09:15:23 mourrain Exp $ 00005 ********************************************************************/ 00006 #ifndef realroot_NUMERICS_EPSILON_HPP 00007 #define realroot_NUMERICS_EPSILON_HPP 00008 #include <realroot/rounding_mode.hpp> 00009 //-------------------------------------------------------------------- 00010 namespace mmx { 00011 //-------------------------------------------------------------------- 00012 namespace numerics 00013 { 00014 /* epsilon<T>::result is a numerical zero */ 00015 struct false_t{}; 00016 struct true_t {}; 00017 template < typename T > struct inexact { typedef false_t result_t; }; 00018 template <> struct inexact<long double>{ typedef true_t result_t; }; 00019 template < typename T > struct epsilon { 00020 static T result; 00021 static T _init_(const true_t&) { 00022 volatile T half(0.5), curr(1.0), one(1.0), prev, eps(1.0); 00023 do 00024 { 00025 prev = curr; 00026 eps *= half; 00027 curr = one+eps; 00028 } 00029 while ((curr!=1.0)&&(curr!=prev)); 00030 return eps; 00031 }; 00032 static T _init_(const false_t&) { return T(0); }; 00033 static T _init_() { return _init_(typename inexact< typename LongVersion<T>::result_t >::result_t()); }; 00034 }; 00035 template < typename T > T epsilon<T>::result = epsilon<T>::_init_(); 00036 }; 00037 //-------------------------------------------------------------------- 00038 } //namespace mmx 00039 /********************************************************************/ 00040 #endif //