Claw 1.7.0
|
00001 /* 00002 CLAW - a C++ Library Absolutely Wonderful 00003 00004 CLAW is a free library without any particular aim but being useful to 00005 anyone. 00006 00007 Copyright (C) 2005-2011 Julien Jorge 00008 00009 This library is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU Lesser General Public 00011 License as published by the Free Software Foundation; either 00012 version 2.1 of the License, or (at your option) any later version. 00013 00014 This library is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public 00020 License along with this library; if not, write to the Free Software 00021 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00022 00023 contact: julien.jorge@gamned.org 00024 */ 00030 #ifndef __CLAW_REAL_NUMBER_HPP__ 00031 #define __CLAW_REAL_NUMBER_HPP__ 00032 00033 #include <iostream> 00034 #include <limits> 00035 00036 namespace claw 00037 { 00038 template<typename T> 00039 class real_number; 00040 } 00041 00042 template<typename T> 00043 std::istream& operator>>( std::istream& is, claw::real_number<T>& self ); 00044 00045 namespace claw 00046 { 00051 template<typename T> 00052 struct make_epsilon 00053 { 00054 static T value( T v ) 00055 { 00056 return std::abs(v) <= 1 ? 00057 std::numeric_limits<T>::epsilon() : 00058 std::abs(v) * std::numeric_limits<T>::epsilon(); 00059 } 00060 }; // struct make_epsilon 00061 00066 template<typename T> 00067 class real_number 00068 { 00069 friend 00070 std::istream& ::operator>> <>( std::istream& is, real_number<T>& self ); 00071 00072 public: 00073 typedef T value_type; 00074 typedef real_number<T> self_type; 00075 00076 public: 00077 real_number(); 00078 real_number( const value_type& v ); 00079 real_number( const self_type& that ); 00080 00081 self_type abs() const; 00082 00083 bool operator<( const self_type& that ) const; 00084 bool operator<=( const self_type& that ) const; 00085 bool operator>( const self_type& that ) const; 00086 bool operator>=( const self_type& that ) const; 00087 bool operator==( const self_type& that ) const; 00088 bool operator!=( const self_type& that ) const; 00089 00090 self_type operator+( const self_type& that ) const; 00091 self_type operator-( const self_type& that ) const; 00092 self_type operator*( const self_type& that ) const; 00093 self_type operator/( const self_type& that ) const; 00094 00095 self_type& operator+=( const self_type& that ); 00096 self_type& operator-=( const self_type& that ); 00097 self_type& operator*=( const self_type& that ); 00098 self_type& operator/=( const self_type& that ); 00099 00100 std::ostream& output( std::ostream& os ) const; 00101 00102 template<typename U> 00103 operator U() const; 00104 00105 private: 00107 value_type m_value; 00108 00110 value_type m_epsilon; 00111 00112 }; // class real_number 00113 } // namespace claw 00114 00115 namespace std 00116 { 00117 template<typename T> 00118 struct numeric_limits< claw::real_number<T> >: 00119 public numeric_limits<T> 00120 { 00121 00122 }; // struct numeric_limits 00123 00124 template<typename T> 00125 claw::real_number<T> abs( const claw::real_number<T>& v ); 00126 } // namespace std 00127 00128 // unary minus 00129 template<typename T> 00130 claw::real_number<T> operator-( const claw::real_number<T>& self ); 00131 00132 template<typename T> 00133 claw::real_number<T> operator-( T v, const claw::real_number<T>& self ); 00134 00135 template<typename T> 00136 std::ostream& operator<<( std::ostream& os, const claw::real_number<T>& self ); 00137 template<typename T> 00138 std::istream& operator>>( std::istream& is, claw::real_number<T>& self ); 00139 00140 #include "claw/impl/real_number.tpp" 00141 00142 #endif // __CLAW_REAL_NUMBER_HPP__ 00143