#include <cel_rational.h>
Public Member Functions | |
Rational () | |
Rational (const Int &n) | |
Rational (const Int &n, const Int &d) | |
Rational (const Rational &r) | |
Rational & | operator= (const Rational &r) |
Rational & | operator= (const Int &n) |
void | assign (const Int &n, const Int &d) |
void | normalize () |
Rational & | operator+= (const Rational &r) |
Rational & | operator-= (const Rational &r) |
Rational & | operator*= (const Rational &r) |
Rational & | operator/= (const Rational &r) |
const Rational & | operator++ () |
const Rational & | operator-- () |
Rational | operator+ (const Rational< Int > &r) const |
Rational | operator- (const Rational< Int > &r) const |
Rational | operator* (const Rational< Int > &r) const |
Rational | operator/ (const Rational< Int > &r) const |
bool | operator< (const Rational &r) const |
bool | operator<= (const Rational &r) const |
bool | operator== (const Rational &r) const |
bool | operator!= (const Rational &r) const |
bool | operator> (const Rational &r) const |
bool | operator>= (const Rational &r) const |
Rational | reciprocal () const |
void | serialize (Stream *inStream, size_t inLevel, Endian inEndian) const |
void | deserialize (Stream *inStream, size_t inLevel, Endian inEndian) |
Public Attributes | |
Int | num |
Int | den |
Rational template struct stores a fraction value.
The following is a sample use of this struct.
The following is not allowed due to C++'s restriction:
You should place the Rational instance first:
This struct also provides serialize / deserialize methods and its own DataTraits to support serialization/deserialization. This struct could be used with SimpleArray and DataArray.
For data compatibility with TIFF 6.0 Specification, this library provides TIFF_RATIONAL and TIFF_SRATIONAL structure.
Portion of this code is inspired by Boost C++ libraries:
© Copyright Paul Moore 1999. Permission to copy, use, modify, sell and distribute this software is granted provided this copyright notice appears in all copies. This software is provided "as is" without express or implied warranty, and with no claim as to its suitability for any purpose.
|
inline |
Default constructor; it initializes the value to 0 (0/1).
Referenced by Celartem::Rational< Int >::reciprocal().
|
inline |
This constructor initializes the value with the integral value.
n | The value. |
|
inline |
This constructor initializes the value with the specified numerator/denominator value.
n | The numerator value. |
d | The denominator value. |
|
inline |
This constructor initializes the value with the specified Rational value.
r | The value. |
|
inline |
This method assigns the specified numerator/denominator value.
This method is slightly faster than initializing the value by copy-operator.
n | The numerator value. |
d | The denominator value. |
|
inline |
This method is just a helper function to deal with SerializableData template. For more information, see SerializableData.
|
inline |
This method normalizes the value stored in this instance.
This function is useful when you directly overwrite the value of num and/or den.
Please note that all assignment methods (constructors, copy-operators and assign method) internally do normalization and you don't have to call this method after calling them.
If the denominator is 0, this method throws an Exception with errInvalidState .
Referenced by Celartem::Rational< Int >::assign(), and Celartem::Rational< Int >::Rational().
|
inline |
This method is provided for the purpose of comparing Rational values.
ture
if the value is not equal to r.This method does not work if either of the Rational instances are not normalized. If the value is not normalized, you should call normalize before calling this method.
|
inline |
This function multiplies the value by the specified Rational value.
r | The values to multiply with. |
|
inline |
This method multiplies this value and the specified Rational value together and store the product into this instance.
r | The value to multiply with. |
|
inline |
This function adds the Rational values.
r | The values to add. |
|
inline |
This method add 1 to the value.
|
inline |
This method add the specified Rational value to this value.
r | The value to add. |
|
inline |
This function subtract the Rational value from this value.
r | The value to subtract. |
|
inline |
This method subtract 1 from the value.
|
inline |
This method subtract the specified Rational value from this value.
r | The value to subtract. |
|
inline |
This function divides the value by the specified Rational value.
r | The divider. |
|
inline |
This method divides this value by the specified Rational value and store the product into this instance.
If the divider value is 0, this method throws an Exception with errDivByZero .
r | The divider value. |
|
inline |
This method is provided for the purpose of comparing Rational values.
ture
if the value is less than r.This method does not work if either of the Rational instances are not normalized. If the value is not normalized, you should call normalize before calling this method.
|
inline |
This method is provided for the purpose of comparing Rational values.
ture
if the value is no more than r.This method does not work if either of the Rational instances are not normalized. If the value is not normalized, you should call normalize before calling this method.
|
inline |
This method set the specified value.
r | The value. |
|
inline |
This constructor initializes the value with the specified integral value.
n | The value. |
|
inline |
This method is provided for the purpose of comparing Rational values.
ture
if the value is equal to r.This method does not work if either of the Rational instances are not normalized. If the value is not normalized, you should call normalize before calling this method.
|
inline |
This method is provided for the purpose of comparing Rational values.
ture
if the value is greater than r.This method does not work if either of the Rational instances are not normalized. If the value is not normalized, you should call normalize before calling this method.
|
inline |
This method is provided for the purpose of comparing Rational values.
ture
if the value is no less than r.This method does not work if either of the Rational instances are not normalized. If the value is not normalized, you should call normalize before calling this method.
|
inline |
This method calculates the reciprocal value.
|
inline |
This method is just a helper function to deal with SerializableData template. For more information, see SerializableData.
Int Celartem::Rational< Int >::den |
Denominator. Although you can access to the numerator value directly, you should keep the value normalized or calculation results are not predictable.
Referenced by Celartem::Rational< Int >::assign(), Celartem::Rational< Int >::deserialize(), Celartem::Rational< Int >::normalize(), Celartem::Rational< Int >::operator!=(), Celartem::Rational< Int >::operator*=(), Celartem::Rational< Int >::operator++(), Celartem::Rational< Int >::operator+=(), Celartem::Rational< Int >::operator--(), Celartem::Rational< Int >::operator-=(), Celartem::Rational< Int >::operator/=(), Celartem::Rational< Int >::operator<(), Celartem::Rational< Int >::operator=(), Celartem::Rational< Int >::operator==(), Celartem::Rational< Int >::reciprocal(), and Celartem::Rational< Int >::serialize().
Int Celartem::Rational< Int >::num |
Numerator. Although you can access to the numerator value directly, you should keep the value normalized or calculation results are not predictable.
Referenced by Celartem::Rational< Int >::assign(), Celartem::Rational< Int >::deserialize(), Celartem::Rational< Int >::normalize(), Celartem::Rational< Int >::operator!=(), Celartem::Rational< Int >::operator*=(), Celartem::Rational< Int >::operator++(), Celartem::Rational< Int >::operator+=(), Celartem::Rational< Int >::operator--(), Celartem::Rational< Int >::operator-=(), Celartem::Rational< Int >::operator/=(), Celartem::Rational< Int >::operator<(), Celartem::Rational< Int >::operator=(), Celartem::Rational< Int >::operator==(), Celartem::Rational< Int >::reciprocal(), and Celartem::Rational< Int >::serialize().