|
CLAW Library (a C++ Library Absolutely Wonderful) 1.5.5
|
Custom precision real numbers. More...
#include <real_number.hpp>
Public Types | |
| typedef T | value_type |
| typedef real_number< T > | self_type |
Public Member Functions | |
| real_number () | |
| Constructuor. | |
| real_number (const value_type &v) | |
| Constructor. | |
| real_number (const self_type &that) | |
| Copy constructor. | |
| self_type | abs () const |
| Get the absolute value of the number. | |
| bool | operator< (const self_type &that) const |
| Tell if this number is stricty lower than an other number. | |
| bool | operator<= (const self_type &that) const |
| Tell if this number is lower or equal to an other number. | |
| bool | operator> (const self_type &that) const |
| Tell if this number is stricty greater than an other number. | |
| bool | operator>= (const self_type &that) const |
| Tell if this number is greater or equal to an other number. | |
| bool | operator== (const self_type &that) const |
| Tell if this number is equal to an other number. | |
| bool | operator!= (const self_type &that) const |
| Tell if this number is not equal to an other number. | |
| self_type | operator+ (const self_type &that) const |
| Sum two numbers. | |
| self_type | operator- (const self_type &that) const |
| Get the difference of two numbers. | |
| self_type | operator* (const self_type &that) const |
| Multiply two numbers. | |
| self_type | operator/ (const self_type &that) const |
| Divide by an other number. | |
| self_type & | operator+= (const self_type &that) |
| Add an other number. | |
| self_type & | operator-= (const self_type &that) |
| Subtract an other number. | |
| self_type & | operator*= (const self_type &that) |
| Multiply by an other number. | |
| self_type & | operator/= (const self_type &that) |
| Divide by an other number. | |
| std::ostream & | output (std::ostream &os) const |
| Output the value in a stream. | |
| template<typename U > | |
| operator U () const | |
| Cast the value. | |
Private Attributes | |
| value_type | m_value |
| The value of the number. | |
| value_type | m_epsilon |
| Precision applied to operators. | |
Friends | |
| std::istream & | operator>> (std::istream &is, real_number< T > &self) |
| Read a number from a stream. | |
Custom precision real numbers.
Definition at line 67 of file real_number.hpp.
| typedef real_number<T> claw::real_number< T >::self_type |
Definition at line 74 of file real_number.hpp.
| typedef T claw::real_number< T >::value_type |
Definition at line 73 of file real_number.hpp.
| claw::real_number< T >::real_number | ( | ) |
Constructuor.
Definition at line 37 of file real_number.tpp.
| claw::real_number< T >::real_number | ( | const value_type & | v | ) |
| claw::real_number< T >::real_number | ( | const self_type & | that | ) |
Copy constructor.
| that | The instance to copy from. |
Definition at line 61 of file real_number.tpp.
| claw::real_number< T >::self_type claw::real_number< T >::abs | ( | ) | const |
Get the absolute value of the number.
Definition at line 72 of file real_number.tpp.
References std::abs().
Referenced by std::abs().
Cast the value.
Definition at line 281 of file real_number.tpp.
{
return (U)m_value;
} // real_number::operator U()
| bool claw::real_number< T >::operator!= | ( | const self_type & | that | ) | const |
Tell if this number is not equal to an other number.
| that | The other number. |
Definition at line 155 of file real_number.tpp.
{
return !((*this) == that);
} // real_number::operator!=()
| claw::real_number< T >::self_type claw::real_number< T >::operator* | ( | const self_type & | that | ) | const |
Multiply two numbers.
| that | The other number. |
Definition at line 191 of file real_number.tpp.
References claw::real_number< T >::m_value.
| claw::real_number< T >::self_type & claw::real_number< T >::operator*= | ( | const self_type & | that | ) |
Multiply by an other number.
| that | The other number. |
Definition at line 243 of file real_number.tpp.
References claw::real_number< T >::m_value, and claw::make_epsilon< T >::value().
| claw::real_number< T >::self_type claw::real_number< T >::operator+ | ( | const self_type & | that | ) | const |
Sum two numbers.
| that | The other number. |
Definition at line 167 of file real_number.tpp.
References claw::real_number< T >::m_value.
| claw::real_number< T >::self_type & claw::real_number< T >::operator+= | ( | const self_type & | that | ) |
Add an other number.
| that | The other number. |
Definition at line 215 of file real_number.tpp.
References claw::real_number< T >::m_value, and claw::make_epsilon< T >::value().
| claw::real_number< T >::self_type claw::real_number< T >::operator- | ( | const self_type & | that | ) | const |
Get the difference of two numbers.
| that | The other number. |
Definition at line 179 of file real_number.tpp.
References claw::real_number< T >::m_value.
| claw::real_number< T >::self_type & claw::real_number< T >::operator-= | ( | const self_type & | that | ) |
Subtract an other number.
| that | The other number. |
Definition at line 229 of file real_number.tpp.
References claw::real_number< T >::m_value, and claw::make_epsilon< T >::value().
| claw::real_number< T >::self_type claw::real_number< T >::operator/ | ( | const self_type & | that | ) | const |
Divide by an other number.
| that | The other number. |
Definition at line 203 of file real_number.tpp.
References claw::real_number< T >::m_value.
| claw::real_number< T >::self_type & claw::real_number< T >::operator/= | ( | const self_type & | that | ) |
Divide by an other number.
| that | The other number. |
Definition at line 257 of file real_number.tpp.
References claw::real_number< T >::m_value, and claw::make_epsilon< T >::value().
| bool claw::real_number< T >::operator< | ( | const self_type & | that | ) | const |
Tell if this number is stricty lower than an other number.
| that | The other number. |
Definition at line 83 of file real_number.tpp.
References claw::real_number< T >::m_epsilon, and claw::real_number< T >::m_value.
{
if ( that.m_value == std::numeric_limits<value_type>::infinity() )
return m_value != std::numeric_limits<value_type>::infinity();
else if ( that.m_value == -std::numeric_limits<value_type>::infinity() )
return false;
else if ( m_value == std::numeric_limits<value_type>::infinity() )
return false;
else if ( m_value == -std::numeric_limits<value_type>::infinity() )
return that.m_value != -std::numeric_limits<value_type>::infinity();
else
return m_value < (that.m_value - std::max(m_epsilon, that.m_epsilon));
} // real_number::operator<()
| bool claw::real_number< T >::operator<= | ( | const self_type & | that | ) | const |
Tell if this number is lower or equal to an other number.
| that | The other number. |
Definition at line 103 of file real_number.tpp.
{
return !(that < *this);
} // real_number::operator<=()
| bool claw::real_number< T >::operator== | ( | const self_type & | that | ) | const |
Tell if this number is equal to an other number.
| that | The other number. |
Definition at line 136 of file real_number.tpp.
References std::abs(), claw::real_number< T >::m_epsilon, and claw::real_number< T >::m_value.
{
if ( that.m_value == std::numeric_limits<value_type>::infinity() )
return m_value == std::numeric_limits<value_type>::infinity();
else if ( that.m_value == -std::numeric_limits<value_type>::infinity() )
return m_value == -std::numeric_limits<value_type>::infinity();
else if ( m_value == that.m_value )
return true;
else
return std::abs(m_value - that.m_value)
<= std::max(m_epsilon, that.m_epsilon);
} // real_number::operator==()
| bool claw::real_number< T >::operator> | ( | const self_type & | that | ) | const |
Tell if this number is stricty greater than an other number.
| that | The other number. |
Definition at line 114 of file real_number.tpp.
{
return that < *this;
} // real_number::operator>()
| bool claw::real_number< T >::operator>= | ( | const self_type & | that | ) | const |
Tell if this number is greater or equal to an other number.
| that | The other number. |
Definition at line 125 of file real_number.tpp.
{
return that <= *this;
} // real_number::operator>=()
| std::ostream & claw::real_number< T >::output | ( | std::ostream & | os | ) | const |
Output the value in a stream.
| os | The stream in which the value is written. |
Definition at line 270 of file real_number.tpp.
Referenced by operator<<().
{
return os << m_value;
} // real_number::output()
| std::istream& operator>> | ( | std::istream & | is, |
| real_number< T > & | self | ||
| ) | [friend] |
Read a number from a stream.
| is | The stream from which the value is read. |
| self | The number. |
Definition at line 339 of file real_number.tpp.
{
return is >> self.m_value;
} // operator>>()
value_type claw::real_number< T >::m_epsilon [private] |
Precision applied to operators.
Definition at line 110 of file real_number.hpp.
Referenced by claw::real_number< T >::operator<(), and claw::real_number< T >::operator==().
value_type claw::real_number< T >::m_value [private] |
The value of the number.
Definition at line 107 of file real_number.hpp.
Referenced by claw::real_number< T >::operator*(), claw::real_number< T >::operator*=(), claw::real_number< T >::operator+(), claw::real_number< T >::operator+=(), claw::real_number< T >::operator-(), claw::real_number< T >::operator-=(), claw::real_number< T >::operator/(), claw::real_number< T >::operator/=(), claw::real_number< T >::operator<(), and claw::real_number< T >::operator==().
1.7.3