Developer documentation

system_epsilon.hpp
Go to the documentation of this file.
1 /********************************************************************
2  * This file is part of the source code of the realroot library.
3  * Author(s): J.P. Pavone, GALAAD, INRIA
4  * $Id: epsilon.H,v 1.1 2005/07/11 09:15:23 mourrain Exp $
5  ********************************************************************/
6 #ifndef realroot_NUMERICS_EPSILON_HPP
7 #define realroot_NUMERICS_EPSILON_HPP
9 //--------------------------------------------------------------------
10 namespace mmx {
11 //--------------------------------------------------------------------
12 namespace numerics
13 {
14  /* epsilon<T>::result is a numerical zero */
15  struct false_t{};
16  struct true_t {};
17  template < typename T > struct inexact { typedef false_t result_t; };
18  template <> struct inexact<long double>{ typedef true_t result_t; };
19  template < typename T > struct epsilon {
20  static T result;
21  static T _init_(const true_t&) {
22  volatile T half(0.5), curr(1.0), one(1.0), prev, eps(1.0);
23  do
24  {
25  prev = curr;
26  eps *= half;
27  curr = one+eps;
28  }
29  while ((curr!=1.0)&&(curr!=prev));
30  return eps;
31  };
32  static T _init_(const false_t&) { return T(0); };
33  static T _init_() { return _init_(typename inexact< typename LongVersion<T>::result_t >::result_t()); };
34  };
35  template < typename T > T epsilon<T>::result = epsilon<T>::_init_();
36 };
37 //--------------------------------------------------------------------
38 } //namespace mmx
39 /********************************************************************/
40 #endif //
Definition: system_epsilon.hpp:19
T result_t
Definition: rounding_mode.hpp:28
static T _init_()
Definition: system_epsilon.hpp:33
Definition: system_epsilon.hpp:15
static T _init_(const true_t &)
Definition: system_epsilon.hpp:21
static T _init_(const false_t &)
Definition: system_epsilon.hpp:32
static T result
Definition: system_epsilon.hpp:20
false_t result_t
Definition: system_epsilon.hpp:17
Definition: system_epsilon.hpp:17
true_t result_t
Definition: system_epsilon.hpp:18
Definition: array.hpp:12
Definition: system_epsilon.hpp:16
Home