rational< T > Class Template Reference

Represent a rational number (fraction) as a numerator and denominator. More...

#include <rational.hpp>

List of all members.

Public Types

typedef T value_type
 Convenience typedef for the integral type of the numerator and denominator.

Public Member Functions

 rational (value_type num=0)
 rational (value_type num, value_type den)
 rational (double r)
template<class U>
 rational (rational< U > const &that)
 Copy from a different type of rational.
value_type numerator () const
 Return the numerator.
value_type denominator () const
 Return the denominator.
template<class U>
as () const
 Convert the rational number to another type, especially floating-point.
rationaloperator= (value_type)
 Assignment of an integer.
template<class U>
rationaloperator= (rational< U > const &rhs)
 Assignment of a rational with a different size.
rationaloperator+= (rational const &rhs)
 Addition assignment operator.
rationaloperator+= (value_type const &rhs)
 Addition assignment operator.
rationaloperator-= (rational const &rhs)
 Subtraction assignment operator.
rationaloperator-= (value_type const &rhs)
 Subtraction assignment operator.
rationaloperator *= (rational const &rhs)
 Multiplication assignment operator.
rationaloperator *= (value_type const &rhs)
 Multiplication assignment operator.
rationaloperator/= (rational const &rhs)
 Division assignment operator.
rationaloperator/= (value_type const &rhs)
 Division assignment operator.
rationaloperator++ ()
 Pre-increment.
rationaloperator-- ()
 Pre-decrement.
rational operator++ (int)
 Post-increment.
rational operator-- (int)
 Post-decrement.

Classes

class  zero_denominator
 Exception class if the denominator is ever zero. More...


Detailed Description

template<class T>
class rational< T >

Represent a rational number (fraction) as a numerator and denominator.

Definition at line 16 of file rational.hpp.


Constructor & Destructor Documentation

template<class T>
rational< T >::rational ( value_type  num = 0  )  [inline]

Default constructor and constructor from a single value. As a default constructor, initializes to zero. Otherwise, initializes to the integer num.

Parameters:
num The integer value to use as the initial value

Definition at line 33 of file rational.hpp.

template<class T>
rational< T >::rational ( value_type  num,
value_type  den 
) [inline]

Construct a rational number

Parameters:
num numerator
den denominator
Exceptions:
zero_denominator if den == 0

Definition at line 106 of file rational.hpp.

template<class T>
rational< T >::rational ( double  r  )  [inline]

Initialize the rational number with an approximation of r

Parameters:
r the initial value

Definition at line 114 of file rational.hpp.


The documentation for this class was generated from the following file:
Generated on Sun Nov 30 09:53:23 2008 for Exploring C++ - Final Forms of Key Examples by  doxygen 1.5.3