rational.hpp File Reference

#include "config.hpp"
#include <iostream>
#include <cstdlib>
#include <sstream>
#include <string>
#include <cctype>
#include <cmath>
#include <functional>
#include "type_traits.hpp"
#include "type_pair_traits.hpp"
#include "exception.hpp"
#include "factory.hpp"
#include "cmp.hpp"
#include "io.hpp"
#include "powerest.hpp"
#include "big_int.hpp"
#include "std_import.hpp"
#include "rational.cpp"

Go to the source code of this file.

Namespaces

namespace  Arageli
namespace  std

Classes

class  Arageli::rational_base
 Base for all rationals. More...
class  Arageli::rational_base::exception
 Exception of all rationals numbers. More...
exception  Arageli::rational_base::exception::std
class  Arageli::rational< T >
 Implementation of a Rational Number. More...
struct  Arageli::select_numer< T >
 Unary functor: selects a numerator of an argument of type rational. More...
struct  Arageli::select_denom< T >
 Unary functor: selects a denominator of an argument of type rational. More...
struct  Arageli::factory< rational< T1 > >
class  std::numeric_limits< Arageli::rational< T > >
 Specialization of standard template std::numeric_limits for rationals. More...
struct  Arageli::type_traits< rational< T > >
 Specialization of type_traits for rational. More...

Standard arithmetic operations.

template<typename T1, typename T2>
rational< T1 > Arageli::operator+ (const rational< T1 > &b, const rational< T2 > &c)
template<typename T1, typename T2>
rational< T1 > Arageli::operator- (const rational< T1 > &b, const rational< T2 > &c)
template<typename T1, typename T2>
rational< T1 > Arageli::operator * (const rational< T1 > &b, const rational< T2 > &c)
template<typename T1, typename T2>
rational< T1 > Arageli::operator/ (const rational< T1 > &b, const rational< T2 > &c)
template<typename T1, typename T2>
rational< T1 > Arageli::operator% (const rational< T1 > &b, const rational< T2 > &c)

Standard arithmetic operations.

template<typename T1, typename T2>
rational< T1 > & Arageli::operator+= (rational< T1 > &a, const rational< T2 > &b)
template<typename T1, typename T2>
rational< T1 > & Arageli::operator+= (rational< T1 > &a, const T2 &b)
template<typename T1, typename T2>
rational< T1 > Arageli::operator+ (const rational< T1 > &a, const T2 &b)
template<typename T1, typename T2>
rational< T1 > Arageli::operator+ (const T2 &a, const rational< T1 > &b)
template<typename T1, typename T2>
rational< T1 > & Arageli::operator-= (rational< T1 > &a, const rational< T2 > &b)
template<typename T1, typename T2>
rational< T1 > & Arageli::operator-= (rational< T1 > &a, const T2 &b)
template<typename T1, typename T2>
rational< T1 > Arageli::operator- (const rational< T1 > &a, const T2 &b)
template<typename T1, typename T2>
rational< T1 > Arageli::operator- (const T2 &a, const rational< T1 > &b)
template<typename T1, typename T2>
rational< T1 > & Arageli::operator *= (rational< T1 > &a, const rational< T2 > &b)
template<typename T1, typename T2>
rational< T1 > & Arageli::operator *= (rational< T1 > &a, const T2 &b)
template<typename T1, typename T2>
rational< T1 > Arageli::operator * (const rational< T1 > &a, const T2 &b)
template<typename T1, typename T2>
rational< T1 > Arageli::operator * (const T2 &a, const rational< T1 > &b)
template<typename T1, typename T2>
rational< T1 > & Arageli::operator/= (rational< T1 > &a, const rational< T2 > &b)
template<typename T1, typename T2>
rational< T1 > & Arageli::operator/= (rational< T1 > &a, const T2 &b)
template<typename T1, typename T2>
rational< T1 > Arageli::operator/ (const rational< T1 > &a, const T2 &b)
template<typename T1, typename T2>
rational< T1 > Arageli::operator/ (const T2 &a, const rational< T1 > &b)
template<typename T1, typename T2>
rational< T1 > & Arageli::operator%= (rational< T1 > &a, const rational< T2 > &b)
template<typename T1, typename T2>
rational< T1 > & Arageli::operator%= (rational< T1 > &a, const T2 &b)
template<typename T1, typename T2>
rational< T1 > Arageli::operator% (const rational< T1 > &a, const T2 &b)
template<typename T1, typename T2>
rational< T1 > Arageli::operator% (const T2 &a, const rational< T1 > &b)

Standard comparision operators.

template<typename T1, typename T2>
bool Arageli::operator< (const rational< T1 > &a, const rational< T2 > &b)
template<typename T1, typename T2>
bool Arageli::operator< (const rational< T1 > &a, const T2 &b)
template<typename T1, typename T2>
bool Arageli::operator< (const T1 &a, const rational< T2 > &b)
template<typename T1, typename T2>
bool Arageli::operator> (const rational< T1 > &a, const rational< T2 > &b)
template<typename T1, typename T2>
bool Arageli::operator> (const rational< T1 > &a, const T2 &b)
template<typename T1, typename T2>
bool Arageli::operator> (const T1 &a, const rational< T2 > &b)
template<typename T1, typename T2>
bool Arageli::operator== (const rational< T1 > &a, const rational< T2 > &b)
template<typename T1, typename T2>
bool Arageli::operator== (const rational< T1 > &a, const T2 &b)
template<typename T1, typename T2>
bool Arageli::operator== (const T1 &a, const rational< T2 > &b)
template<typename T1, typename T2>
bool Arageli::operator!= (const rational< T1 > &a, const rational< T2 > &b)
template<typename T1, typename T2>
bool Arageli::operator!= (const rational< T1 > &a, const T2 &b)
template<typename T1, typename T2>
bool Arageli::operator!= (const T1 &a, const rational< T2 > &b)
template<typename T1, typename T2>
bool Arageli::operator<= (const rational< T1 > &a, const rational< T2 > &b)
template<typename T1, typename T2>
bool Arageli::operator<= (const rational< T1 > &a, const T2 &b)
template<typename T1, typename T2>
bool Arageli::operator<= (const T1 &a, const rational< T2 > &b)
template<typename T1, typename T2>
bool Arageli::operator>= (const rational< T1 > &a, const rational< T2 > &b)
template<typename T1, typename T2>
bool Arageli::operator>= (const rational< T1 > &a, const T2 &b)
template<typename T1, typename T2>
bool Arageli::operator>= (const T1 &a, const rational< T2 > &b)

Defines

#define _ARAGELI_RATIONAL_OPERATOR_TO(TYPE)   operator TYPE () const { return double(*this); }
#define _ARAGELI_RATIONAL_OPERS(OPER)
#define _ARAGELI_RATIONAL_CMP1(OPER)
#define ARAGELI_INCLUDE_CPP_WITH_EXPORT_TEMPLATE_RATIONAL

Functions

template<typename T, typename Ch, typename ChT>
std::basic_ostream< Ch, ChT > & Arageli::output_list (std::basic_ostream< Ch, ChT > &out, const rational< T > &x, const Ch *first_bracket=rational_output_list_first_bracket_default, const Ch *second_bracket=rational_output_list_second_bracket_default, const Ch *separator=rational_output_list_separator_default)
template<typename T, typename Ch, typename ChT>
std::basic_istream< Ch, ChT > & Arageli::input_list (std::basic_istream< Ch, ChT > &in, rational< T > &x, const Ch *first_bracket=rational_input_list_first_bracket_default, const Ch *second_bracket=rational_input_list_second_bracket_default, const Ch *separator=rational_input_list_separator_default)
template<typename T, typename Ch, typename ChT>
std::basic_ostream< Ch, ChT > & Arageli::output_default (std::basic_ostream< Ch, ChT > &out, const rational< T > &x, const Ch *oblique=rational_output_default_oblique_default)
template<typename T, typename Ch, typename ChT>
std::basic_istream< Ch, ChT > & Arageli::input_default (std::basic_istream< Ch, ChT > &in, rational< T > &x, const Ch *oblique=rational_input_default_oblique_default)
template<typename T, typename Ch, typename ChT>
std::basic_ostream< Ch, ChT > & Arageli::operator<< (std::basic_ostream< Ch, ChT > &out, const rational< T > &x)
 Reads a rational from a string notation.
template<typename T, typename Ch, typename ChT>
std::basic_istream< Ch, ChT > & Arageli::operator>> (std::basic_istream< Ch, ChT > &in, rational< T > &x)
 Writes a rational to a string notation.
template<typename T1, typename T2>
int Arageli::cmp (const rational< T1 > &a, const rational< T2 > &b)
 Comparison of two rationals.
template<typename T>
int Arageli::sign (const rational< T > &x)
template<typename T>
bool Arageli::is_coprime (const rational< T > &a, const rational< T > &b)
template<typename T>
rational< T > Arageli::gcd (const rational< T > &a, const rational< T > &b)
template<typename T>
Arageli::ifloor (const rational< T > &x)
 Floor of x.
template<typename T>
Arageli::iceil (const rational< T > &x)
 Ceiling of x.
template<typename T>
rational< T > Arageli::frac (const rational< T > &x)
 Fractional part of x.
template<typename T1>
bool Arageli::is_null (const rational< T1 > &x)
template<typename T1>
rational< T1 > Arageli::opposite (const rational< T1 > &x)
template<typename T1>
rational< T1 > & Arageli::opposite (const rational< T1 > &x, rational< T1 > *y)
template<typename T1>
rational< T1 > & Arageli::opposite (rational< T1 > *x)
template<typename T1>
rational< T1 > Arageli::inverse (const rational< T1 > &x)
template<typename T1>
rational< T1 > & Arageli::inverse (const rational< T1 > &x, rational< T1 > *y)
template<typename T1>
rational< T1 > & Arageli::inverse (rational< T1 > *x)
template<typename T1>
std::ostream & Arageli::output_polynom_first (std::ostream &out, const rational< T1 > &x)
template<typename T1>
std::ostream & Arageli::output_polynom_internal (std::ostream &out, const rational< T1 > &x)
template<typename T1>
std::ostream & Arageli::output_pow (std::ostream &out, const rational< T1 > &x)
template<typename T1>
std::istream & Arageli::input_polynom_first (std::istream &in, rational< T1 > &x)
template<typename T1>
std::istream & Arageli::input_polynom_internal (std::istream &in, rational< T1 > &x)
template<typename T1>
std::istream & Arageli::input_pow (std::istream &in, rational< T1 > &x)
template<typename T>
rational< T > Arageli::abs (const rational< T > &x)
 Absolute value of x.
template<typename T>
rational< T > Arageli::floor (const rational< T > &x)
 Floor of x.
template<typename T>
rational< T > Arageli::ceil (const rational< T > &x)
 Ceiling of x.
template<typename T>
Arageli::rational< T > std::abs (const Arageli::rational< T > &x)
 Absolute value of x.
template<typename T>
Arageli::rational< T > std::floor (const Arageli::rational< T > &x)
 Floor of x.
template<typename T>
Arageli::rational< T > std::ceil (const Arageli::rational< T > &x)
 Ceiling of x.
template<typename T>
void std::swap (Arageli::rational< T > &a, Arageli::rational< T > &b)
 Swaps two rationals without actully copying (if possible).
template<typename T1, typename T2>
void std::swap (Arageli::rational< T1 > &a, Arageli::rational< T2 > &b)
 Swaps two rationals without actully copying (if possible).

Variables

const char * Arageli::rational_output_list_first_bracket_default
const char * Arageli::rational_output_list_second_bracket_default
const char * Arageli::rational_output_list_separator_default
const char * Arageli::rational_input_list_first_bracket_default
const char * Arageli::rational_input_list_second_bracket_default
const char * Arageli::rational_input_list_separator_default
const char * Arageli::rational_output_default_oblique_default
const char * Arageli::rational_input_default_oblique_default


Detailed Description

Rational numbers. The module containes implementation for a rational number.

Definition in file rational.hpp.


Define Documentation

#define _ARAGELI_RATIONAL_CMP1 ( OPER   ) 

Value:

template <typename T1, typename T2>                         \
    inline bool operator OPER                                   \
    (const rational<T1>& a, const rational<T2>& b)              \
    { return cmp(a, b) OPER 0; }                                \
                                                                \
    template <typename T1, typename T2>                         \
    inline bool operator OPER                                   \
    (const rational<T1>& a, const T2& b)                        \
    { return cmp(a, rational<T2>(b)) OPER 0; }  /* WARNING! */  \
                                                                \
    template <typename T1, typename T2>                         \
    inline bool operator OPER                                   \
    (const T1& a, const rational<T2>& b)                        \
    { return cmp(rational<T1>(a), b) OPER 0; }

Definition at line 515 of file rational.hpp.

#define _ARAGELI_RATIONAL_OPERATOR_TO ( TYPE   )     operator TYPE () const { return double(*this); }

Converts from rational to integer base type T by division. Returns the result of (integer) division numerator/denominator.

Definition at line 136 of file rational.hpp.

#define _ARAGELI_RATIONAL_OPERS ( OPER   ) 

Value:

template <typename T1, typename T2>         \
    inline rational<T1>& operator OPER##=       \
    (rational<T1>& a, const rational<T2>& b)    \
    { return a = a OPER b; }                    \
                                                \
    template <typename T1, typename T2>         \
    inline rational<T1>& operator OPER##=       \
    (rational<T1>& a, const T2& b)              \
    { return a = a OPER rational<T1>(b); }      \
                                                \
    template <typename T1, typename T2>         \
    inline rational<T1> operator OPER           \
    (const rational<T1>& a, const T2& b)        \
    { return a OPER rational<T1>(b); }          \
                                                \
    template <typename T1, typename T2>         \
    inline rational<T1> operator OPER           \
    (const T2& a, const rational<T1>& b)        \
    { return rational<T1>(a) OPER b; }

Definition at line 444 of file rational.hpp.

#define ARAGELI_INCLUDE_CPP_WITH_EXPORT_TEMPLATE_RATIONAL

Definition at line 960 of file rational.hpp.


Generated on Thu Aug 31 17:38:18 2006 for Arageli by  doxygen 1.4.7