| Home | Libraries | People | FAQ | More

## Reference

### Header `<boost/ratio/config.hpp>`

    // Configuration macros
    #define BOOST_RATIO_VERSION
    #define BOOST_RATIO_EXTENSIONS
    #define BOOST_RATIO_PROVIDES_DEPRECATED_FEATURES_SINCE_V2_0_0
    #define BOOST_RATIO_DONT_PROVIDE_DEPRECATED_FEATURES_SINCE_V2_0_0
    #define BOOST_RATIO_USES_STATIC_ASSERT
    #define BOOST_RATIO_USES_MPL_ASSERT
    #define BOOST_RATIO_USES_ARRAY_ASSERT

#### Extensions

When `BOOST_RATIO_EXTENSIONS` is defined, Boost.Ratio provides in addition some extension to the C++ standard, see below.

#### Deprecated

When `BOOST_RATIO_PROVIDES_DEPRECATED_FEATURES_SINCE_V2_0_0` is defined the deprecated features stated as DEPRECATED V2 are provided.

When `BOOST_RATIO_DONT_PROVIDE_DEPRECATED_FEATURES_SINCE_V2_0_0` is defined the deprecated features stated as DEPRECATED V2 are NOT provided.

#### Version

`BOOST_RATIO_VERSION` stands for the Boost.Ratio version which can be 1 or 2. The default up to 1.55 is version 1. Since 1.56 it will be 2.

When `BOOST_RATIO_VERSION` is 1 `BOOST_RATIO_PROVIDES_DEPRECATED_FEATURES_SINCE_V2_0_0` is defined by default.

When `BOOST_RATIO_VERSION` is 2 `BOOST_RATIO_DONT_PROVIDE_DEPRECATED_FEATURES_SINCE_V2_0_0` is defined by default.

#### Static Assert

When BOOST_NO_STATIC_ASSERT is defined, the user can select the way static assertions are reported. Define

- `BOOST_RATIO_USES_STATIC_ASSERT` to use Boost.StaticAssert.
- `BOOST_RATIO_USES_MPL_ASSERT` to use Boost.MPL static assertions.
- `BOOST_RATIO_USES_ARRAY_ASSERT` to use Boost.Ratio internal static assertions.

The default behavior is as if `BOOST_RATIO_USES_ARRAY_ASSERT` was defined.

When `BOOST_RATIO_USES_MPL_ASSERT` is not defined the following symbols are defined as shown:

    #define BOOST_RATIO_OVERFLOW_IN_ADD "overflow in ratio add"
    #define BOOST_RATIO_OVERFLOW_IN_SUB "overflow in ratio sub"
    #define BOOST_RATIO_OVERFLOW_IN_MUL "overflow in ratio mul"
    #define BOOST_RATIO_OVERFLOW_IN_DIV "overflow in ratio div"
    #define BOOST_RATIO_NUMERATOR_IS_OUT_OF_RANGE "ratio numerator is out of range"
    #define BOOST_RATIO_DIVIDE_BY_0 "ratio divide by 0"
    #define BOOST_RATIO_DENOMINATOR_IS_OUT_OF_RANGE "ratio denominator is out of range"

Depending upon the static assertion system used, a hint as to the failing assertion will appear in some form in the compiler diagnostic output.

### C++0x Recommendation

#### Header `<boost/ratio.hpp>`

This header includes all the ratio related header files

    #include <boost/ratio/ratio.hpp>
    #include <boost/ratio/ratio_io.hpp>
    #include <boost/ratio/rational_constant.hpp>

#### Header `<boost/ratio/ratio_fwd.hpp>`

This header provides forward declarations for the `<boost/ratio/ratio.hpp>` file.

    namespace boost  {

        template <boost::intmax_t N, boost::intmax_t D = 1> class ratio;

        // ratio arithmetic
        template <class R1, class R2> struct ratio_add;
        template <class R1, class R2> struct ratio_subtract;
        template <class R1, class R2> struct ratio_multiply;
        template <class R1, class R2> struct ratio_divide;
        template <class R> struct ratio_negate;
        template <class R> struct ratio_sign;
        template <class R> struct ratio_abs;
        template <class R1, class R2> struct ratio_gcd;
        template <class R1, class R2> struct ratio_lcm;

        // ratio comparison
        template <class R1, class R2> struct ratio_equal;
        template <class R1, class R2> struct ratio_not_equal;
        template <class R1, class R2> struct ratio_less;
        template <class R1, class R2> struct ratio_less_equal;
        template <class R1, class R2> struct ratio_greater;
        template <class R1, class R2> struct ratio_greater_equal;

        // convenience SI typedefs
        typedef ratio<1LL, 1000000000000000000LL> atto;
        typedef ratio<1LL,    1000000000000000LL> femto;
        typedef ratio<1LL,       1000000000000LL> pico;
        typedef ratio<1LL,          1000000000LL> nano;
        typedef ratio<1LL,             1000000LL> micro;
        typedef ratio<1LL,                1000LL> milli;
        typedef ratio<1LL,                 100LL> centi;
        typedef ratio<1LL,                  10LL> deci;
        typedef ratio<                 10LL, 1LL> deca;
        typedef ratio<                100LL, 1LL> hecto;
        typedef ratio<               1000LL, 1LL> kilo;
        typedef ratio<            1000000LL, 1LL> mega;
        typedef ratio<         1000000000LL, 1LL> giga;
        typedef ratio<      1000000000000LL, 1LL> tera;
        typedef ratio<   1000000000000000LL, 1LL> peta;
        typedef ratio<1000000000000000000LL, 1LL> exa;
    }

#### Header `<boost/ratio/ratio.hpp>`

`ratio` is a facility which is useful in specifying compile-time rational constants. Compile-time rational arithmetic is supported with protection against overflow and divide by zero. Such a facility is very handy to efficiently represent 1/3 of a nanosecond, or to specify an inch in terms of meters (for example 254/10000 meters - which `ratio` will reduce to 127/5000 meters).

##### Class Template `ratio<>`

    template <boost::intmax_t N, boost::intmax_t D>
    class ratio {
    public:
        static const boost::intmax_t num;
        static const boost::intmax_t den;
        typedef ratio<num, den> type;

        #ifdef BOOST_RATIO_EXTENSIONS
        typedef mpl::rational_c_tag tag;
        typedef boost::rational<boost::intmax_t> value_type;
        typedef boost::intmax_t num_type;
        typedef boost::intmax_t den_type;

        ratio() = default;

        template <intmax_t _N2, intmax_t _D2>
        ratio(const ratio<_N2, _D2>&);

        template <intmax_t _N2, intmax_t _D2>
        ratio& operator=(const ratio<_N2, _D2>&);

        static value_type value();
        value_type operator()() const;
        #endif
    };

A diagnostic will be emitted if `ratio` is instantiated with `D == 0`, or if the absolute value of `N` or `D` cannot be represented. Note: These rules ensure that infinite ratios are avoided and that for any negative input, there exists a representable value of its absolute value which is positive. In a two's complement representation, this excludes the most negative value.

The members num and den will be normalized values of the template arguments N and D computed as follows. Let `gcd` denote the greatest common divisor of `N`'s absolute value and of `D`'s absolute value. Then:

- `num` has the value `sign(N)*sign(D)*abs(N)/gcd`.
- `den` has the value `abs(D)/gcd`.

The nested typedef `type` denotes the normalized form of this `ratio` type. It should be used when the normalized form of the template arguments are required, since the arguments are not necessarily normalized.

Two `ratio` classes ``ratio`<N1,D1>` and ``ratio`<N2,D2>` have the same normalized form if ``ratio`<N1,D1>::type` is the same type as ``ratio`<N2,D2>::type`

###### Construction and Assignment

Included only if `BOOST_RATIO_EXTENSIONS` is defined.

Default Constructor

    ratio()=default;

Effects: Constructs a `ratio` object.

Copy Constructor

    template <intmax_t N2, intmax_t D2>
      ratio(const ratio<N2, D2>& r);

Effects: Constructs a `ratio` object.

Remarks: This constructor will not participate in overload resolution unless `r` has the same normalized form as `*this`.

Assignement

    template <intmax_t N2, intmax_t D2>
      ratio& operator=(const ratio<N2, D2>& r);

Effects: Assigns a `ratio` object.

Returns: *this.

Remarks: This operator will not participate in overload resolution unless `r` has the same normalized form as `*this`.

###### MPL Numeric Metafunctions

Included only if `BOOST_RATIO_EXTENSIONS` is defined.

In order to work with Boost.MPL numeric metafunctions as a Rational Constant, the following has beed added:

    typedef mpl::rational_c_tag tag;
    typedef boost::rational<boost::intmax_t> value_type;
    typedef boost::intmax_t num_type;
    typedef boost::intmax_t den_type;

###### Observers

Included only if `BOOST_RATIO_EXTENSIONS` is defined.

    static value_type value();
    value_type operator()() const;

Returns: value_type(num,den);

##### `ratio` Arithmetic

For each of the class templates in this section, each template parameter refers to a `ratio`. If the implementation is unable to form the indicated `ratio` due to overflow, a diagnostic will be issued.

###### `ratio_add<>`

    template <class R1, class R2> struct ratio_add {
       typedef [/see below] type;
    };

The nested typedef `type` is a synonym for ``ratio`<R1::num * R2::den + R2::num * R1::den, R1::den * R2::den>::type`.

###### `ratio_subtract<>`

    template <class R1, class R2> struct ratio_subtract {
       typedef  [/see below]  type;
    };

The nested typedef `type` is a synonym for ``ratio`<R1::num * R2::den - R2::num * R1::den, R1::den * R2::den>::type`.

###### `ratio_multiply<>`

    template <class R1, class R2> struct ratio_multiply {
       typedef  [/see below]  type;
    };

The nested typedef `type` is a synonym for ``ratio`<R1::num * R2::num, R1::den * R2::den>::type`.

###### `ratio_divide<>`

    template <class R1, class R2> struct ratio_divide {
       typedef  [/see below]  type;
    };

The nested typedef `type` is a synonym for ``ratio`<R1::num * R2::den, R2::num * R1::den>::type`.

###### `ratio_negate<>`

This extension of the C++ standard helps in the definition of some Boost.MPL numeric metafunctions.

    template <class R> struct ratio_negate {
       typedef  [/see below]  type;
    };

The nested typedef `type` is a synonym for ``ratio`<-R::num, R::den>::type`.

###### `ratio_abs<>`

This extension of the C++ standard helps in the definition of some Boost.MPL numeric metafunctions.

    template <class R> struct ratio_abs {
       typedef  [/see below]  type;
    };

The nested typedef `type` is a synonym for ``ratio`<abs_c<intmax_t,R::num>::value, R::den>::type`.

###### `ratio_sign<>`

This extension of the C++ standard helps in the definition of some Boost.MPL numeric metafunctions.

    template <class R> struct ratio_sign {
       typedef  [/see below]  type;
    };

The nested typedef `type` is a synonym for `sign_c<intmax_t,R::num>::type`.

###### `ratio_gcd<>`

This extension of the C++ standard helps in the definition of some Boost.MPL numeric metafunctions.

    template <class R1, class R2> struct ratio_gcd {
       typedef  [/see below]  type;
    };

The nested typedef `type` is a synonym for `ratio<gcd_c<intmax_t, R1::num, R2::num>::value, mpl::lcm_c<intmax_t, R1::den, R2::den>::value>::type`.

###### `ratio_lcm<>`

This extension of the C++ standard helps in the definition of some Boost.MPL numeric metafunctions.

    template <class R1, class R2> struct ratio_lcm {
       typedef  [/see below]  type;
    };

The nested typedef `type` is a synonym for `ratio<lcm_c<intmax_t, R1::num, R2::num>::value, gcd_c<intmax_t, R1::den, R2::den>::value>::type`.

##### `ratio` Comparison

###### `ratio_equal<>`

    template <class R1, class R2>  struct ratio_equal
        : public boost::integral_constant<bool, [/see below] > {};

If R1::num == R2::num && R1::den == R2::den, ratio_equal derives from true_type, else derives from false_type.

###### `ratio_not_equal<>`

    template <class R1, class R2>  struct ratio_not_equal
        : public boost::integral_constant<bool, !ratio_equal<R1, R2>::value> {};

###### `ratio_less<>`

    template <class R1, class R2>
    struct ratio_less
        : public boost::integral_constant<bool, [/see below] > {};

If R1::num * R2::den < R2::num * R1::den, ratio_less derives from true_type, else derives from false_type.

###### `ratio_less_equal<>`

    template <class R1, class R2> struct ratio_less_equal
        : public boost::integral_constant<bool, !ratio_less<R2, R1>::value> {};

###### `ratio_greater<>`

    template <class R1, class R2> struct ratio_greater
        : public boost::integral_constant<bool, ratio_less<R2, R1>::value> {};

###### `ratio_greater_equal<>`

    template <class R1, class R2> struct ratio_greater_equal
        : public boost::integral_constant<bool, !ratio_less<R1, R2>::value> {};

##### SI typedefs

The International System of Units specifies twenty SI prefixes. Boost.Ratio defines all except `yocto`, `zepto`, `zetta`, and `yotta`

    // convenience SI typedefs
    typedef ratio<1LL, 1000000000000000000LL> atto;
    typedef ratio<1LL,    1000000000000000LL> femto;
    typedef ratio<1LL,       1000000000000LL> pico;
    typedef ratio<1LL,          1000000000LL> nano;
    typedef ratio<1LL,             1000000LL> micro;
    typedef ratio<1LL,                1000LL> milli;
    typedef ratio<1LL,                 100LL> centi;
    typedef ratio<1LL,                  10LL> deci;
    typedef ratio<                 10LL, 1LL> deca;
    typedef ratio<                100LL, 1LL> hecto;
    typedef ratio<               1000LL, 1LL> kilo;
    typedef ratio<            1000000LL, 1LL> mega;
    typedef ratio<         1000000000LL, 1LL> giga;
    typedef ratio<      1000000000000LL, 1LL> tera;
    typedef ratio<   1000000000000000LL, 1LL> peta;
    typedef ratio<1000000000000000000LL, 1LL> exa;

##### Limitations

The following are limitations of Boost.Ratio relative to the specification in the C++0x draft standard:

- Four of the SI units typedefs -- `yocto`, `zepto`, `zetta`, and `yotta` -- are to be conditionally supported, if the range of `intmax_t` allows, but are not supported by Boost.Ratio.
- Ratio values should be of type static `constexpr intmax_t` (see Ratio values should be constexpr), but for compiler not supporting `constexpr` today, Boost.Ratio uses `static const intmax_t` instead.
- Rational arithmetic should use template aliases (see Rational Arithmetic should use template aliases), but those are not available in C++03, so inheritance is used instead.

##### Extensions

When `BOOST_RATIO_EXTENSIONS` is defined Boost.Ratio provides the following extensions:

- Extends the requirements of the C++0x draft standard by making the copy constructor and copy assignment operator have the same normalized form (see copy constructor and assignment between ratios having the same normalized form).
- More C++ standard like metafunctions applied to ratio types, like __static_abs or __static_negate.
- An __Boost_Mpl rational constant concept and the associated __Boost_Mpl arithmetic and comparison specializations including __numeric_cast, __plus, __equal_to between others.

### Ratio I/O

#### Header `<boost/ratio/ratio_io.hpp>`

This header provides `ratio_string<>` which can generate a textual representation of a `ratio<>` in the form of a `std::basic_string<>`. These strings can be useful for I/O.

    namespace boost {
        template <class Ratio, class charT> struct ratio_string;

        template <> struct ratio_string<atto, char>;
        template <> struct ratio_string<atto, char16_t>;
        template <> struct ratio_string<atto, char32_t>;
        template <> struct ratio_string<atto, wchar_t>;

        template <> struct ratio_string<femto, char>;
        template <> struct ratio_string<femto, char16_t>;
        template <> struct ratio_string<femto, char32_t>;
        template <> struct ratio_string<femto, wchar_t>;

        template <> struct ratio_string<pico, char>;
        template <> struct ratio_string<pico, char16_t>;
        template <> struct ratio_string<pico, char32_t>;
        template <> struct ratio_string<pico, wchar_t>;

        template <> struct ratio_string<nano, char>;
        template <> struct ratio_string<nano, char16_t>;
        template <> struct ratio_string<nano, char32_t>;
        template <> struct ratio_string<nano, wchar_t>;

        template <> struct ratio_string<micro, char>;
        template <> struct ratio_string<micro, char16_t>;
        template <> struct ratio_string<micro, char32_t>;
        template <> struct ratio_string<micro, wchar_t>;

        template <> struct ratio_string<milli, char>;
        template <> struct ratio_string<milli, char16_t>;
        template <> struct ratio_string<milli, char32_t>;
        template <> struct ratio_string<milli, wchar_t>;

        template <> struct ratio_string<centi, char>;
        template <> struct ratio_string<centi, char16_t>;
        template <> struct ratio_string<centi, char32_t>;
        template <> struct ratio_string<centi, wchar_t>;

        template <> struct ratio_string<deci, char>;
        template <> struct ratio_string<deci, char16_t>;
        template <> struct ratio_string<deci, char32_t>;
        template <> struct ratio_string<deci, wchar_t>;

        template <> struct ratio_string<deca, char>;
        template <> struct ratio_string<deca, char16_t>;
        template <> struct ratio_string<deca, char32_t>;
        template <> struct ratio_string<deca, wchar_t>;

        template <> struct ratio_string<hecto, char>;
        template <> struct ratio_string<hecto, char16_t>;
        template <> struct ratio_string<hecto, char32_t>;
        template <> struct ratio_string<hecto, wchar_t>;

        template <> struct ratio_string<kilo, char>;
        template <> struct ratio_string<kilo, char16_t>;
        template <> struct ratio_string<kilo, char32_t>;
        template <> struct ratio_string<kilo, wchar_t>;

        template <> struct ratio_string<mega, char>;
        template <> struct ratio_string<mega, char16_t>;
        template <> struct ratio_string<mega, char32_t>;
        template <> struct ratio_string<mega, wchar_t>;

        template <> struct ratio_string<giga, char>;
        template <> struct ratio_string<giga, char16_t>;
        template <> struct ratio_string<giga, char32_t>;
        template <> struct ratio_string<giga, wchar_t>;

        template <> struct ratio_string<tera, char>;
        template <> struct ratio_string<tera, char16_t>;
        template <> struct ratio_string<tera, char32_t>;
        template <> struct ratio_string<tera, wchar_t>;

        template <> struct ratio_string<peta, char>;
        template <> struct ratio_string<peta, char16_t>;
        template <> struct ratio_string<peta, char32_t>;
        template <> struct ratio_string<peta, wchar_t>;

        template <> struct ratio_string<exa, char>;
        template <> struct ratio_string<exa, char16_t>;
        template <> struct ratio_string<exa, char32_t>;
        template <> struct ratio_string<exa, wchar_t>;
    }

##### Template Class `ratio_string<>`

    template <class Ratio, class CharT>
    struct ratio_string
    {
        static std::basic_string<CharT> symbol();
        static std::basic_string<CharT> prefix();
        static std::basic_string<CharT> short_name(); // DEPRECATED V2
        static std::basic_string<CharT> long_name(); // DEPRECATED V2
    };

The class template ratio_string provides textual representations of the associated ratio appropriate for the character type charT.

The primary template provides generic strings. Specializations provide the same static member functions but these functions return the English SI prefix and symbol names as specified by the General Conference on Weights and Measures.

###### Static Member function `prefix()`

    template<class Ratio, class CharT>
    basic_string<charT>
    ratio_string<Ratio, CharT>::prefix();

Returns: A basic_string of the form: [Ratio::num/Ratio::den]

Example: `ratio_string<ratio<2, 60>, wchar_t>::prefix()` returns `L"[1/30]"`.

###### Static Member function `symbol()`

    template<class Ratio, class CharT>
    basic_string<charT>
    ratio_string<Ratio, CharT>::symbol();

Returns: prefix().

###### Static Member function `long_name()` DEPRECATED V2

    template<class Ratio, class CharT>
    basic_string<charT>
    ratio_string<Ratio, CharT>::long_name();

Returns: prefix().

###### Static Member function `short_name()` DEPRECATED V2

    template<class Ratio, class CharT>
    basic_string<charT>
    ratio_string<Ratio, CharT>::short_name();

Returns: symbol().

##### Specializations for `ratio_string<>`

With compilers supporting char16_t and char32_t and with a standard library don't providing std::u16string and std::u32string you will need to define the macros BOOST_NO_CXX11_U16STRING and BOOST_NO_CXX11_U32STRING until Boost.Config defines them.

For each specialization the table gives the return value for `prefix()` and `symbol()`.

Table 22.1. The return values of specializations of ratio_string

Specialization | `prefix()` | `symbol()`
--- | --- | ---
`ratio_string<atto, char>` | `"atto"` | `"a"`
`ratio_string<atto, char16_t>` | `u"atto"` | `u"a"`
`ratio_string<atto, char32_t>` | `U"atto"` | `U"a"`
`ratio_string<atto, wchar_t>` | `L"atto"` | `L"a"`
`ratio_string<femto, char>` | `"femto"` | `"f"`
`ratio_string<femto, char16_t>` | `u"femto"` | `u"f"`
`ratio_string<femto, char32_t>` | `U"femto"` | `U"f"`
`ratio_string<femto, wchar_t>` | `L"femto"` | `L"f"`
`ratio_string<pico, char>` | `"pico"` | `"p"`
`ratio_string<pico, char16_t>` | `u"pico"` | `u"p"`
`ratio_string<pico, char32_t>` | `U"pico"` | `U"p"`
`ratio_string<pico, wchar_t>` | `L"pico"` | `L"p"`
`ratio_string<nano, char>` | `"nano"` | `"a"`
`ratio_string<nano, char16_t>` | `u"nano"` | `u"a"`
`ratio_string<nano, char32_t>` | `U"nano"` | `U"a"`
`ratio_string<nano, wchar_t>` | `L"nano"` | `L"a"`
`ratio_string<micro, char>` | `"micro"` | `u8"\u00B5"`
`ratio_string<micro, char16_t>` | `u"micro"` | `u"\u00B5"`
`ratio_string<micro, char32_t>` | `U"micro"` | `U"\u00B5"`
`ratio_string<micro, wchar_t>` | `L"micro"` | `Lu8"\u00B5"`
`ratio_string<milli, char>` | `"milli"` | `"m"`
`ratio_string<milli, char16_t>` | `u"milli"` | `u"m"`
`ratio_string<milli, char32_t>` | `U"milli"` | `U"m"`
`ratio_string<milli, wchar_t>` | `L"milli"` | `L"m"`
`ratio_string<centi, char>` | `"centi"` | `"c"`
`ratio_string<centi, char16_t>` | `u"centi"` | `u"c"`
`ratio_string<centi, char32_t>` | `U"centi"` | `U"c"`
`ratio_string<centi, wchar_t>` | `L"centi"` | `L"c"`
`ratio_string<deci, char>` | `"deci"` | `"d"`
`ratio_string<deci, char16_t>` | `u"deci"` | `u"d"`
`ratio_string<deci, char32_t>` | `U"deci"` | `U"d"`
`ratio_string<deci, wchar_t>` | `L"deci"` | `L"d"`
`ratio_string<deca, char>` | `"deca"` | `"da"`
`ratio_string<deca, char16_t>` | `u"deca"` | `u"da"`
`ratio_string<deca, char32_t>` | `U"deca"` | `U"da"`
`ratio_string<deca, wchar_t>` | `L"deca"` | `L"da"`
`ratio_string<hecto, char>` | `"hecto"` | `"h"`
`ratio_string<hecto, char16_t>` | `u"hecto"` | `u"h"`
`ratio_string<hecto, char32_t>` | `U"hecto"` | `U"h"`
`ratio_string<hecto, wchar_t>` | `L"hecto"` | `L"h"`
`ratio_string<kilo, char>` | `"kilo"` | `"k"`
`ratio_string<kilo, char16_t>` | `u"kilo"` | `u"k"`
`ratio_string<kilo, char32_t>` | `U"kilo"` | `U"k"`
`ratio_string<kilo, wchar_t>` | `L"kilo"` | `L"k"`
`ratio_string<mega, char>` | `"mega"` | `"M"`
`ratio_string<mega, char16_t>` | `u"mega"` | `u"M"`
`ratio_string<mega, char32_t>` | `U"mega"` | `U"M"`
`ratio_string<mega, wchar_t>` | `L"mega"` | `L"M"`
`ratio_string<giga, char>` | `"giga"` | `"G"`
`ratio_string<giga, char16_t>` | `u"giga"` | `u"G"`
`ratio_string<giga, char32_t>` | `U"giga"` | `U"G"`
`ratio_string<giga, wchar_t>` | `L"giga"` | `L"G"`
`ratio_string<tera, char>` | `"tera"` | `"T"`
`ratio_string<tera, char16_t>` | `u"tera"` | `u"T"`
`ratio_string<tera, char32_t>` | `U"tera"` | `U"T"`
`ratio_string<tera, wchar_t>` | `L"tera"` | `L"T"`
`ratio_string<peta, char>` | `"peta"` | `"P"`
`ratio_string<peta, char16_t>` | `u"peta"` | `u"P"`
`ratio_string<peta, char32_t>` | `U"peta"` | `U"P"`
`ratio_string<peta, wchar_t>` | `L"peta"` | `L"P"`
`ratio_string<exa, char>` | `"exa"` | `"E"`
`ratio_string<exa, char16_t>` | `u"exa"` | `u"E"`
`ratio_string<exa, char32_t>` | `U"exa"` | `U"E"`
`ratio_string<exa, wchar_t>` | `L"exa"` | `L"E"`

### Rational Constant

#### Rational Constant Concept

###### Description

A Rational Constant is a holder class for a compile-time value of a rational type. Every Rational Constant is also a nullary Metafunction, returning itself. A rational constant object is implicitly convertible to the corresponding run-time value of the rational type.

###### Expression requirements

In the following table and subsequent specifications, r is a model of Rational Constant.

Expression | Type | Complexity
--- | --- | ---
`r::tag` | `rational_c_tag` | Constant time
`r::value_type` | A rational type | Constant time
`r::num_type` | An integral type | Constant time
`r::den_type` | An integral type | Constant time
`r::num` | An Integral constant expression | Constant time
`r::den` | An Integral constant expression | Constant time
`r::type` | Rational Constant | Constant time
`r::value_type const c=r()` |  | Constant time

###### Expression semantics

Expression | Semantics
--- | ---
`r::tag` | r's tag type; r::tag::value is r's conversion rank.
`r::value_type` | A cv-unqualified type of `r()`
`r::num_type` | A cv-unqualified type of `r::num`
`r::den_type` | A cv-unqualified type of `r::den`
`r::num` | The numerator of the rational constant
`r::den` | The denominator of the rational constant
`r::type` | equal_to<n::type,n>::value == true.
`r::value_type const c=r()` | `r::value_type const c=r::value_type(r::num,r::den)`

###### Models

- `ratio`<>

#### Header `<boost/ratio/mpl/rational_constant.hpp>`

This header includes all the rational constant related header files

    #include <boost/ratio/mpl/rational_c_tag.hpp>
    #include <boost/ratio/mpl/numeric_cast.hpp>
    #include <boost/ratio/mpl/arithmetic.hpp>
    #include <boost/ratio/mpl/comparison.hpp>

#### Header `<boost/ratio/mpl/rational_c_tag.hpp>`

    namespace boost {
    namespace mpl {

        struct rational_c_tag : int_<10> {};

    }
    }

#### Header `<boost/ratio/mpl/numeric_cast.hpp>`

    namespace boost {
    namespace mpl {

        template<> struct numeric_cast< integral_c_tag,rational_c_tag >;

    }
    }

##### `mpl::numeric_cast<>` Specialization

A Integral Constant is seen as a ratio with numerator the Integral Constant value and denominator 1.

    template<> struct numeric_cast< integral_c_tag,rational_c_tag >
    {
        template< typename N > struct apply
            : ratio< N::value, 1 >
        {
        };
    };

#### Header `<boost/ratio/mpl/arithmetic.hpp>`

This header includes all the rational constant arithmetic MPL specializations.

    #include <boost/ratio/mpl/plus.hpp>
    #include <boost/ratio/mpl/minus.hpp>
    #include <boost/ratio/mpl/times.hpp>
    #include <boost/ratio/mpl/divides.hpp>
    #include <boost/ratio/mpl/negate.hpp>
    #include <boost/ratio/mpl/abs.hpp>
    #include <boost/ratio/mpl/sign.hpp>
    #include <boost/ratio/mpl/gcd.hpp>
    #include <boost/ratio/mpl/lcm.hpp>

#### Header `<boost/ratio/mpl/plus.hpp>`

    namespace boost {
    namespace mpl {
        template<>
        struct plus_impl< rational_c_tag,rational_c_tag >;
    }
    }

##### `mpl::plus_impl<>` Specialization

The specialization relays on the `ratio_add` template class.

    template<>
    struct plus_impl< rational_c_tag,rational_c_tag >
    {
        template< typename R1, typename R2 > struct apply
            : ratio_add<R1, R2>
        {
        };
    };

#### Header `<boost/ratio/mpl/minus.hpp>`

    namespace boost {
    namespace mpl {
        template<>
        struct minus_impl< rational_c_tag,rational_c_tag >;
    }
    }

##### `mpl::minus_impl<>` Specialization

The specialization relays on the `ratio_subtract` template class.

    template<>
    struct plus_impl< rational_c_tag,rational_c_tag >
    {
        template< typename R1, typename R2 > struct apply
            : ratio_subtract<R1, R2>
        {
        };
    };

#### Header `<boost/ratio/mpl/times.hpp>`

    namespace boost {
    namespace mpl {
        template<>
        struct times_impl< rational_c_tag,rational_c_tag >;
    }
    }

##### `mpl::times_impl<>` Specialization

The specialization relays on the `ratio_multiply` template class.

    template<>
    struct times_impl< rational_c_tag,rational_c_tag >
    {
        template< typename R1, typename R2 > struct apply
            : ratio_multiply<R1, R2>
        {
        };
    };

#### Header `<boost/ratio/mpl/divides.hpp>`

    namespace boost {
    namespace mpl {
        template<>
        struct divides_impl< rational_c_tag,rational_c_tag >;
    }
    }

##### `mpl::divides_impl<>` Specialization

The specialization relays on the `ratio_divide` template class.

    template<>
    struct divides_impl< rational_c_tag,rational_c_tag >
    {
        template< typename R1, typename R2 > struct apply
            : ratio_divide<R1, R2>
        {
        };
    };

#### Header `<boost/ratio/mpl/gcd.hpp>`

    namespace boost {
    namespace mpl {
        template<>
        struct gcd_impl< rational_c_tag,rational_c_tag >;
    }
    }

##### `mpl::gcd_impl<>` Specialization

The specialization relays on the `ratio_gcd` template class.

    template<>
    struct gcd_impl< rational_c_tag,rational_c_tag >
    {
        template< typename R1, typename R2 > struct apply
            : ratio_gcd<R1, R2>
        {
        };
    };

#### Header `<boost/ratio/mpl/lcm.hpp>`

    namespace boost {
    namespace mpl {
        template<>
        struct lcm_impl< rational_c_tag,rational_c_tag >;
    }
    }

##### `mpl::lcm_impl<>` Specialization

The specialization relays on the `ratio_lcm` template class.

    template<>
    struct lcm_impl< rational_c_tag,rational_c_tag >
    {
        template< typename R1, typename R2 > struct apply
            : ratio_lcm<R1, R2>
        {
        };
    };

#### Header `<boost/ratio/mpl/negate.hpp>`

    namespace boost {
    namespace mpl {
        template<>
        struct negate_impl< rational_c_tag >;
    }
    }

##### `mpl::negate_impl<>` Specialization

The specialization relays on the `ratio_negate` template class.

    template<>
    struct negate_impl< rational_c_tag >
    {
        template< typename R > struct apply
            : ratio_negate<R>
        {
        };
    };

#### Header `<boost/ratio/mpl/abs.hpp>`

    namespace boost {
    namespace mpl {
        template<>
        struct abs_impl< rational_c_tag >;
    }
    }

##### `mpl::abs_impl<>` Specialization

The specialization relays on the `ratio_abs` template class.

    template<>
    struct abs_impl< rational_c_tag >
    {
        template< typename R > struct apply
            : ratio_abs<R>
        {
        };
    };

#### Header `<boost/ratio/mpl/sign.hpp>`

    namespace boost {
    namespace mpl {
        template<>
        struct sign_impl< rational_c_tag >;
    }
    }

##### `mpl::sign_impl<>` Specialization

The specialization relays on the `ratio_sign` template class.

    template<>
    struct sign_impl< rational_c_tag >
    {
        template< typename R > struct apply
            : ratio_sign<R>
        {
        };
    };

#### Header `<boost/ratio/mpl/comparison.hpp>`

This header includes all the rational constant comparison MPL specializations.

    #include <boost/ratio/mpl/equal_to.hpp>
    #include <boost/ratio/mpl/not_equal_to.hpp>
    #include <boost/ratio/mpl/less.hpp>
    #include <boost/ratio/mpl/less_equal.hpp>
    #include <boost/ratio/mpl/greater.hpp>
    #include <boost/ratio/mpl/greater_equal.hpp>

#### Header `<boost/ratio/mpl/equal_to.hpp>`

    namespace boost {
    namespace mpl {
        template<>
        struct equal_to_impl< rational_c_tag,rational_c_tag >;
    }
    }

##### `mpl::equal_to_impl<>` Specialization

The specialization relays on the `ratio_equal` template class.

    template<>
    struct equal_to_impl< rational_c_tag,rational_c_tag >
    {
        template< typename R1, typename R2 > struct apply
            : ratio_equal<R1, R2>
        {
        };
    };

#### Header `<boost/ratio/mpl/not_equal_to.hpp>`

    namespace boost {
    namespace mpl {
        template<>
        struct not_equal_to_impl< rational_c_tag,rational_c_tag >;
    }
    }

##### `mpl::not_equal_to_impl<>` Specialization

The specialization relays on the `ratio_not_equal` template class.

    template<>
    struct not_equal_to_impl< rational_c_tag,rational_c_tag >
    {
        template< typename R1, typename R2 > struct apply
            : ratio_not_equal<R1, R2>
        {
        };
    };

#### Header `<boost/ratio/mpl/less.hpp>`

    namespace boost {
    namespace mpl {
        template<>
        struct less_impl< rational_c_tag,rational_c_tag >;
    }
    }

##### `mpl::less_impl<>` Specialization

The specialization relays on the `ratio_less` template class.

    template<>
    struct less_impl< rational_c_tag,rational_c_tag >
    {
        template< typename R1, typename R2 > struct apply
            : ratio_less<R1, R2>
        {
        };
    };

#### Header `<boost/ratio/mpl/less_equal.hpp>`

    namespace boost {
    namespace mpl {
        template<>
        struct less_equal_impl< rational_c_tag,rational_c_tag >;
    }
    }

##### `mpl::less_equal_impl<>` Specialization

The specialization relays on the `ratio_less_equal` template class.

    template<>
    struct less_equal_impl< rational_c_tag,rational_c_tag >
    {
        template< typename R1, typename R2 > struct apply
            : ratio_less_equal<R1, R2>
        {
        };
    };

#### Header `<boost/ratio/mpl/greater.hpp>`

    namespace boost {
    namespace mpl {
        template<>
        struct greater_impl< rational_c_tag,rational_c_tag >;
    }
    }

##### `mpl::greater_impl<>` Specialization

The specialization relays on the `ratio_greater` template class.

    template<>
    struct greater_impl< rational_c_tag,rational_c_tag >
    {
        template< typename R1, typename R2 > struct apply
            : ratio_greater<R1, R2>
        {
        };
    };

#### Header `<boost/ratio/mpl/greater_equal.hpp>`

    namespace boost {
    namespace mpl {
        template<>
        struct greater_equal_impl< rational_c_tag,rational_c_tag >;
    }
    }

##### `mpl::greater_equal_impl<>` Specialization

The specialization relays on the `ratio_greater_equal` template class.

    template<>
    struct greater_equal_impl< rational_c_tag,rational_c_tag >
    {
        template< typename R1, typename R2 > struct apply
            : ratio_greater_equal<R1, R2>
        {
        };
    };