Claw 1.7.3
real_number.hpp
Go to the documentation of this file.
1/*
2 CLAW - a C++ Library Absolutely Wonderful
3
4 CLAW is a free library without any particular aim but being useful to
5 anyone.
6
7 Copyright (C) 2005-2011 Julien Jorge
8
9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Lesser General Public
11 License as published by the Free Software Foundation; either
12 version 2.1 of the License, or (at your option) any later version.
13
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public
20 License along with this library; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
23 contact: julien.jorge@gamned.org
24*/
30#ifndef __CLAW_REAL_NUMBER_HPP__
31#define __CLAW_REAL_NUMBER_HPP__
32
33#include <iostream>
34#include <limits>
35
36namespace claw
37{
38 template<typename T>
39 class real_number;
40}
41
42template<typename T>
43std::istream& operator>>( std::istream& is, claw::real_number<T>& self );
44
45namespace claw
46{
51 template<typename T>
53 {
54 static T value( T v )
55 {
56 return std::abs(v) <= 1 ?
57 std::numeric_limits<T>::epsilon() :
58 std::abs(v) * std::numeric_limits<T>::epsilon();
59 }
60 }; // struct make_epsilon
61
66 template<typename T>
68 {
69 friend
70 std::istream& ::operator>> <>( std::istream& is, real_number<T>& self );
71
72 public:
73 typedef T value_type;
75
76 public:
78 real_number( const value_type& v );
79 real_number( const self_type& that );
80
81 self_type abs() const;
82
83 bool operator<( const self_type& that ) const;
84 bool operator<=( const self_type& that ) const;
85 bool operator>( const self_type& that ) const;
86 bool operator>=( const self_type& that ) const;
87 bool operator==( const self_type& that ) const;
88 bool operator!=( const self_type& that ) const;
89
90 self_type operator+( const self_type& that ) const;
91 self_type operator-( const self_type& that ) const;
92 self_type operator*( const self_type& that ) const;
93 self_type operator/( const self_type& that ) const;
94
95 self_type& operator+=( const self_type& that );
96 self_type& operator-=( const self_type& that );
97 self_type& operator*=( const self_type& that );
98 self_type& operator/=( const self_type& that );
99
100 std::ostream& output( std::ostream& os ) const;
101
102 template<typename U>
103 operator U() const;
104
105 private:
107 value_type m_value;
108
110 value_type m_epsilon;
111
112 }; // class real_number
113} // namespace claw
114
115namespace std
116{
117 template<typename T>
118 struct numeric_limits< claw::real_number<T> >:
119 public numeric_limits<T>
120 {
121
122 }; // struct numeric_limits
123
124 template<typename T>
126} // namespace std
127
128// unary minus
129template<typename T>
130claw::real_number<T> operator-( const claw::real_number<T>& self );
131
132template<typename T>
133claw::real_number<T> operator-( T v, const claw::real_number<T>& self );
134
135template<typename T>
136std::ostream& operator<<( std::ostream& os, const claw::real_number<T>& self );
137template<typename T>
138std::istream& operator>>( std::istream& is, claw::real_number<T>& self );
139
140#include "claw/impl/real_number.tpp"
141
142#endif // __CLAW_REAL_NUMBER_HPP__
143
Custom precision real numbers.
This is the main namespace.
Definition algorithm.hpp:34
This class generates an epsilon value of a given precision.