|
| std::ostream & | operator<< (std::ostream &s, vnl_rational const &r) |
| | formatted output. More...
|
| |
| std::istream & | operator>> (std::istream &s, vnl_rational &r) |
| | simple input. More...
|
| |
| vnl_rational | operator+ (vnl_rational const &r1, vnl_rational const &r2) |
| | Returns the sum of two rational numbers. More...
|
| |
| vnl_rational | operator+ (vnl_rational const &r1, long r2) |
| |
| vnl_rational | operator+ (vnl_rational const &r1, int r2) |
| |
| vnl_rational | operator+ (long r2, vnl_rational const &r1) |
| |
| vnl_rational | operator+ (int r2, vnl_rational const &r1) |
| |
| vnl_rational | operator- (vnl_rational const &r1, vnl_rational const &r2) |
| | Returns the difference of two rational numbers. More...
|
| |
| vnl_rational | operator- (vnl_rational const &r1, long r2) |
| |
| vnl_rational | operator- (vnl_rational const &r1, int r2) |
| |
| vnl_rational | operator- (long r2, vnl_rational const &r1) |
| |
| vnl_rational | operator- (int r2, vnl_rational const &r1) |
| |
| vnl_rational | operator * (vnl_rational const &r1, vnl_rational const &r2) |
| | Returns the product of two rational numbers. More...
|
| |
| vnl_rational | operator * (vnl_rational const &r1, long r2) |
| |
| vnl_rational | operator * (vnl_rational const &r1, int r2) |
| |
| vnl_rational | operator * (long r2, vnl_rational const &r1) |
| |
| vnl_rational | operator * (int r2, vnl_rational const &r1) |
| |
| vnl_rational | operator/ (vnl_rational const &r1, vnl_rational const &r2) |
| | Returns the quotient of two rational numbers. More...
|
| |
| vnl_rational | operator/ (vnl_rational const &r1, long r2) |
| |
| vnl_rational | operator/ (vnl_rational const &r1, int r2) |
| |
| vnl_rational | operator/ (long r1, vnl_rational const &r2) |
| |
| vnl_rational | operator/ (int r1, vnl_rational const &r2) |
| |
| vnl_rational | operator% (vnl_rational const &r1, vnl_rational const &r2) |
| | Returns the remainder of r1 divided by r2. More...
|
| |
| vnl_rational | operator% (vnl_rational const &r1, long r2) |
| |
| vnl_rational | operator% (vnl_rational const &r1, int r2) |
| |
| vnl_rational | operator% (long r1, vnl_rational const &r2) |
| |
| vnl_rational | operator% (int r1, vnl_rational const &r2) |
| |
| bool | operator== (int r1, vnl_rational const &r2) |
| |
| bool | operator== (long r1, vnl_rational const &r2) |
| |
| bool | operator!= (int r1, vnl_rational const &r2) |
| |
| bool | operator!= (long r1, vnl_rational const &r2) |
| |
| bool | operator< (int r1, vnl_rational const &r2) |
| |
| bool | operator< (long r1, vnl_rational const &r2) |
| |
| bool | operator> (int r1, vnl_rational const &r2) |
| |
| bool | operator> (long r1, vnl_rational const &r2) |
| |
| bool | operator<= (int r1, vnl_rational const &r2) |
| |
| bool | operator<= (long r1, vnl_rational const &r2) |
| |
| bool | operator>= (int r1, vnl_rational const &r2) |
| |
| bool | operator>= (long r1, vnl_rational const &r2) |
| |
| long | truncate (vnl_rational const &r) |
| |
| long | floor (vnl_rational const &r) |
| |
| long | ceil (vnl_rational const &r) |
| |
| long | round (vnl_rational const &r) |
| |
| vnl_rational | vnl_math::abs (vnl_rational const &x) |
| |
| vnl_rational | vnl_math::squared_magnitude (vnl_rational const &x) |
| |
| vnl_rational | vnl_math::sqr (vnl_rational const &x) |
| |
| bool | vnl_math::isnan (vnl_rational const &) |
| |
| bool | vnl_math::isfinite (vnl_rational const &x) |
| |
High-precision rational numbers.
The vnl_rational class provides high-precision rational numbers and arithmetic, using the built-in type long, for the numerator and denominator. Implicit conversion to the system defined types short, int, long, float, and double is supported by overloaded operator member functions. Although the rational class makes judicious use of inline functions and deals only with integral values, the user is warned that the rational integer arithmetic class is still considerably slower than the built-in integer data types. If the range of values anticipated will fit into a built-in type, use that instead.
In addition to the original COOL Rational class, vnl_rational is able to represent plus and minus infinity. An other interesting addition is the possibility to construct a rational from a double. This allows for lossless conversion from e.g. double 1.0/3.0 to the rational number 1/3, hence no more rounding errors. This is implemented with continued fraction approximations.
- Author
- Copyright (C) 1991 Texas Instruments Incorporated.
Permission is granted to any individual or institution to use, copy, modify, and distribute this software, provided that this complete copyright and permission notice is maintained, intact, in all copies and supporting documentation.
Texas Instruments Incorporated provides this software "as is" without express or implied warranty.
Modifications
Peter Vanroose, 13 July 2001: Added continued fraction cnstrctr from double
Peter Vanroose, 10 July 2001: corrected operator%=()
Peter Vanroose, 10 July 2001: corrected ceil() and floor() for negative args
Peter Vanroose, 10 July 2001: extended operability range of += by using gcd
Peter Vanroose, 10 July 2001: added abs().
Peter Vanroose, 10 July 2001: removed state data member and added Inf repres
Peter Vanroose, 9 July 2001: ported to vnl from COOL
Peter Vanroose, 11 June 2009: made "*" and "/" robust against int overflow
(actually a full re-implementation, using gcd)
Definition in file vnl_rational.h.