# rational_c

### Synopsis

    template<
          typename IntegerType
        , IntegerType N
        , IntegerType D = 1
        >
    struct rational_c
    {
        typedef rational_c<IntegerType, N, D> type;
        typedef IntegerType integer_type;
        typedef integral_c<IntegerType,N> numerator;
        typedef integral_c<IntegerType,D> denominator;

        static double value();
    };

### Description

A model of Rational Constant.

### Definition

    #include "boost/mpl/math/rational_c.hpp"

### Parameters

Parameter | Requirement | Description
--- | --- | ---
`IntegerType` | An integral type | Type used to represent numerator and denominator.
`N` | A compile time integral constant of type `IntegerType` | Value of numerator.
`D` | A compile time integral constant of type `IntegerType` | Value of denominator.

### Expression semantics

Expression | Expression type | Precondition | Semantics | Postcondition
--- | --- | --- | --- | ---
`rational_c<T,n,d>::value()` | `double` | `static_cast<T>(d) != 0` | Returns `static_cast<double>(static_cast<T>(n)) / static_cast<T>(d)`. |

### Complexity

All operations take amortized constant time.

### Example

      typedef rational_c<int,1,2> half;
      typedef rational_c<int,2,4> half_2;
      typedef rational_c<long,9,15> three_fiths_3;
      typedef rational_plus<three_fiths,half>::type eleven_tenth;
      typedef rational_plus<half,half>::type one;
      typedef rational_c<long,1,8> eighth;
      typedef rational_minus<half,eighth>::type three_eighths;
      typedef rational_multiplies<half,eighth>::type sixteenth;
      typedef rational_divides<eighth,half>::type quarter;

### See also

Rational Constant, Integral Constant, `integral_c`

Table of Contents
Last edited October 30, 2003 2:44 am