High-precision rational numbers. More...
#include <vcl_iostream.h>
#include <vcl_cassert.h>
Go to the source code of this file.
Classes | |
class | vnl_rational |
High-precision rational numbers. More... | |
Functions | |
vcl_ostream & | operator<< (vcl_ostream &s, vnl_rational const &r) |
formatted output. | |
vcl_istream & | operator>> (vcl_istream &s, vnl_rational &r) |
simple input. | |
vnl_rational | operator+ (vnl_rational const &r1, vnl_rational const &r2) |
Returns the sum of two rational numbers. | |
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. | |
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. | |
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. | |
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. | |
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.
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.
long ceil | ( | vnl_rational const & | r | ) | [inline] |
Definition at line 440 of file vnl_rational.h.
long floor | ( | vnl_rational const & | r | ) | [inline] |
Definition at line 439 of file vnl_rational.h.
bool operator!= | ( | int | r1, |
vnl_rational const & | r2 | ||
) | [inline] |
Definition at line 427 of file vnl_rational.h.
bool operator!= | ( | long | r1, |
vnl_rational const & | r2 | ||
) | [inline] |
Definition at line 428 of file vnl_rational.h.
vnl_rational operator% | ( | vnl_rational const & | r1, |
vnl_rational const & | r2 | ||
) | [inline] |
Returns the remainder of r1 divided by r2.
Definition at line 400 of file vnl_rational.h.
vnl_rational operator% | ( | vnl_rational const & | r1, |
long | r2 | ||
) | [inline] |
Definition at line 405 of file vnl_rational.h.
vnl_rational operator% | ( | vnl_rational const & | r1, |
int | r2 | ||
) | [inline] |
Definition at line 410 of file vnl_rational.h.
vnl_rational operator% | ( | long | r1, |
vnl_rational const & | r2 | ||
) | [inline] |
Definition at line 415 of file vnl_rational.h.
vnl_rational operator% | ( | int | r1, |
vnl_rational const & | r2 | ||
) | [inline] |
Definition at line 420 of file vnl_rational.h.
vnl_rational operator* | ( | vnl_rational const & | r1, |
vnl_rational const & | r2 | ||
) | [inline] |
Returns the product of two rational numbers.
Definition at line 346 of file vnl_rational.h.
vnl_rational operator* | ( | vnl_rational const & | r1, |
long | r2 | ||
) | [inline] |
Definition at line 351 of file vnl_rational.h.
vnl_rational operator* | ( | vnl_rational const & | r1, |
int | r2 | ||
) | [inline] |
Definition at line 356 of file vnl_rational.h.
vnl_rational operator* | ( | long | r2, |
vnl_rational const & | r1 | ||
) | [inline] |
Definition at line 361 of file vnl_rational.h.
vnl_rational operator* | ( | int | r2, |
vnl_rational const & | r1 | ||
) | [inline] |
Definition at line 366 of file vnl_rational.h.
vnl_rational operator+ | ( | vnl_rational const & | r1, |
vnl_rational const & | r2 | ||
) | [inline] |
Returns the sum of two rational numbers.
Definition at line 292 of file vnl_rational.h.
vnl_rational operator+ | ( | vnl_rational const & | r1, |
long | r2 | ||
) | [inline] |
Definition at line 297 of file vnl_rational.h.
vnl_rational operator+ | ( | vnl_rational const & | r1, |
int | r2 | ||
) | [inline] |
Definition at line 302 of file vnl_rational.h.
vnl_rational operator+ | ( | long | r2, |
vnl_rational const & | r1 | ||
) | [inline] |
Definition at line 307 of file vnl_rational.h.
vnl_rational operator+ | ( | int | r2, |
vnl_rational const & | r1 | ||
) | [inline] |
Definition at line 312 of file vnl_rational.h.
vnl_rational operator- | ( | vnl_rational const & | r1, |
vnl_rational const & | r2 | ||
) | [inline] |
Returns the difference of two rational numbers.
Definition at line 319 of file vnl_rational.h.
vnl_rational operator- | ( | vnl_rational const & | r1, |
long | r2 | ||
) | [inline] |
Definition at line 324 of file vnl_rational.h.
vnl_rational operator- | ( | vnl_rational const & | r1, |
int | r2 | ||
) | [inline] |
Definition at line 329 of file vnl_rational.h.
vnl_rational operator- | ( | long | r2, |
vnl_rational const & | r1 | ||
) | [inline] |
Definition at line 334 of file vnl_rational.h.
vnl_rational operator- | ( | int | r2, |
vnl_rational const & | r1 | ||
) | [inline] |
Definition at line 339 of file vnl_rational.h.
vnl_rational operator/ | ( | vnl_rational const & | r1, |
vnl_rational const & | r2 | ||
) | [inline] |
Returns the quotient of two rational numbers.
Definition at line 373 of file vnl_rational.h.
vnl_rational operator/ | ( | vnl_rational const & | r1, |
long | r2 | ||
) | [inline] |
Definition at line 378 of file vnl_rational.h.
vnl_rational operator/ | ( | vnl_rational const & | r1, |
int | r2 | ||
) | [inline] |
Definition at line 383 of file vnl_rational.h.
vnl_rational operator/ | ( | long | r1, |
vnl_rational const & | r2 | ||
) | [inline] |
Definition at line 388 of file vnl_rational.h.
vnl_rational operator/ | ( | int | r1, |
vnl_rational const & | r2 | ||
) | [inline] |
Definition at line 393 of file vnl_rational.h.
bool operator< | ( | int | r1, |
vnl_rational const & | r2 | ||
) | [inline] |
Definition at line 429 of file vnl_rational.h.
bool operator< | ( | long | r1, |
vnl_rational const & | r2 | ||
) | [inline] |
Definition at line 430 of file vnl_rational.h.
vcl_ostream & operator<< | ( | vcl_ostream & | s, |
vnl_rational const & | r | ||
) | [inline] |
formatted output.
Definition at line 277 of file vnl_rational.h.
bool operator<= | ( | int | r1, |
vnl_rational const & | r2 | ||
) | [inline] |
Definition at line 433 of file vnl_rational.h.
bool operator<= | ( | long | r1, |
vnl_rational const & | r2 | ||
) | [inline] |
Definition at line 434 of file vnl_rational.h.
bool operator== | ( | int | r1, |
vnl_rational const & | r2 | ||
) | [inline] |
Definition at line 425 of file vnl_rational.h.
bool operator== | ( | long | r1, |
vnl_rational const & | r2 | ||
) | [inline] |
Definition at line 426 of file vnl_rational.h.
bool operator> | ( | int | r1, |
vnl_rational const & | r2 | ||
) | [inline] |
Definition at line 431 of file vnl_rational.h.
bool operator> | ( | long | r1, |
vnl_rational const & | r2 | ||
) | [inline] |
Definition at line 432 of file vnl_rational.h.
bool operator>= | ( | int | r1, |
vnl_rational const & | r2 | ||
) | [inline] |
Definition at line 435 of file vnl_rational.h.
bool operator>= | ( | long | r1, |
vnl_rational const & | r2 | ||
) | [inline] |
Definition at line 436 of file vnl_rational.h.
vcl_istream & operator>> | ( | vcl_istream & | s, |
vnl_rational & | r | ||
) | [inline] |
simple input.
Definition at line 284 of file vnl_rational.h.
long round | ( | vnl_rational const & | r | ) | [inline] |
Definition at line 441 of file vnl_rational.h.
long truncate | ( | vnl_rational const & | r | ) | [inline] |
Definition at line 438 of file vnl_rational.h.
vnl_rational vnl_math_abs | ( | vnl_rational const & | x | ) | [inline] |
Definition at line 443 of file vnl_rational.h.
bool vnl_math_isfinite | ( | vnl_rational const & | x | ) | [inline] |
Definition at line 447 of file vnl_rational.h.
bool vnl_math_isnan | ( | vnl_rational const & | ) | [inline] |
Definition at line 446 of file vnl_rational.h.
vnl_rational vnl_math_sqr | ( | vnl_rational const & | x | ) | [inline] |
Definition at line 445 of file vnl_rational.h.
vnl_rational vnl_math_squared_magnitude | ( | vnl_rational const & | x | ) | [inline] |
Definition at line 444 of file vnl_rational.h.