#include <cel_rational.h>
List of all members.
Detailed Description
template<typename Int>
struct Celartem::Rational< Int >
Rational template struct stores a fraction value.
The following is a sample use of this struct.
Rational<int> a(1,2), b(2,3), c(2);
Rational<int> d = (a + b) / c;
Rational<int> e = d * 3;
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.
- See also:
- TIFF_RATIONAL, TIFF_SRATIONAL
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.
Constructor & Destructor Documentation
This constructor initializes the value with the integral value.
- Parameters:
-
This constructor initializes the value with the specified numerator/denominator value.
- Parameters:
-
| n | The numerator value. |
| d | The denominator value. |
This constructor initializes the value with the specified Rational value.
- Parameters:
-
Member Function Documentation
This method assigns the specified numerator/denominator value.
This method is slightly faster than initializing the value by copy-operator.
- Parameters:
-
| n | The numerator value. |
| d | The denominator value. |
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().
This method is provided for the purpose of comparing Rational values.
- Returns:
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.
This function multiplies the value by the specified Rational value.
- Parameters:
-
| r | The values to multiply with. |
- Returns:
- The result.
This method multiplies this value and the specified Rational value together and store the product into this instance.
- Parameters:
-
| r | The value to multiply with. |
- Returns:
- The reference to this Rational instance.
This function adds the Rational values.
- Parameters:
-
- Returns:
- The result.
This method add 1 to the value.
- Returns:
- The reference to this Rational instance.
This method add the specified Rational value to this value.
- Parameters:
-
- Returns:
- The reference to this Rational instance.
This function subtract the Rational value from this value.
- Parameters:
-
- Returns:
- The result.
This method subtract 1 from the value.
- Returns:
- The reference to this Rational instance.
This method subtract the specified Rational value from this value.
- Parameters:
-
- Returns:
- The reference to this Rational instance.
This function divides the value by the specified Rational value.
- Parameters:
-
- Returns:
- The result.
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 .
- Parameters:
-
- Returns:
- The reference to this Rational instance.
This method is provided for the purpose of comparing Rational values.
- Returns:
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.
This method is provided for the purpose of comparing Rational values.
- Returns:
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.
This constructor initializes the value with the specified integral value.
- Parameters:
-
- Returns:
- The reference to this Rational instance.
This method set the specified value.
- Parameters:
-
- Returns:
- The reference to this Rational instance.
This method is provided for the purpose of comparing Rational values.
- Returns:
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.
This method is provided for the purpose of comparing Rational values.
- Returns:
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.
This method is provided for the purpose of comparing Rational values.
- Returns:
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.
This method calculates the reciprocal value.
- Returns:
- The reciprocal value.
Member Data Documentation
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().
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().
The documentation for this struct was generated from the following file: