mirror of
https://github.com/boostorg/mpl.git
synced 2026-01-26 08:52:21 +01:00
72 lines
3.0 KiB
HTML
72 lines
3.0 KiB
HTML
<!doctype html public "-//ietf//dtd html//en">
|
|
<html><head><title>boost::mpl::rational_c</title>
|
|
<link rel="stylesheet" href="../mpl_wiki.css">
|
|
</head><body bgcolor="white">
|
|
<h1><a href="../Table_of_Contents.html"><img src="../mpl_logo.jpg" alt="[Home]" border=0 align="right"></a>rational_c</h1><h3>Synopsis</h3>
|
|
<p>
|
|
<pre>
|
|
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;
|
|
<p>
|
|
static double value();
|
|
};
|
|
</pre>
|
|
<p>
|
|
<p>
|
|
<h3>Description</h3>
|
|
<p>
|
|
A model of <a href="../Rational_Constant.html">Rational Constant</a>.
|
|
<p>
|
|
<h3>Definition</h3>
|
|
<p>
|
|
<pre>
|
|
#include "<a href="../../../../../boost/mpl/math/rational_c.hpp">boost/mpl/math/rational_c.hpp</a>"
|
|
</pre>
|
|
<p>
|
|
<h3>Parameters</h3>
|
|
<table border="1">
|
|
<tr><th> Parameter </th><th> Requirement </th><th> Description </th></tr>
|
|
<tr><td><code>IntegerType</code></td><td>An integral type</td><td>Type used to represent numerator and denominator. </td></tr>
|
|
<tr><td><code>N</code></td><td>A compile time integral constant of type <code>IntegerType</code></td><td>Value of numerator. </td></tr>
|
|
<tr><td><code>D</code></td><td>A compile time integral constant of type <code>IntegerType</code></td><td>Value of denominator. </td></tr>
|
|
</table>
|
|
<p>
|
|
<h3>Expression semantics</h3>
|
|
<p>
|
|
<table border="1">
|
|
<tr><th> Expression </th><th> Expression type </th><th> Precondition </th><th> Semantics </th><th> Postcondition </th></tr>
|
|
<tr><td><code>rational_c<T,n,d>::value()</code></td><td><code>double</code></td><td><code>static_cast<T>(d) != 0</code></td><td>Returns <code>static_cast<double>(static_cast<T>(n)) / static_cast<T>(d)</code>.</td><td></td></tr>
|
|
</table>
|
|
<p>
|
|
<h3>Complexity</h3>
|
|
<p>
|
|
All operations take amortized constant time.
|
|
<p>
|
|
<h3>Example</h3>
|
|
<p>
|
|
<pre>
|
|
typedef <a href="../Reference/rational_c.html">rational_c</a><int,1,2> half;
|
|
typedef <a href="../Reference/rational_c.html">rational_c</a><int,2,4> half_2;
|
|
typedef <a href="../Reference/rational_c.html">rational_c</a><long,9,15> three_fiths_3;
|
|
typedef rational_plus<three_fiths,half>::type eleven_tenth;
|
|
typedef rational_plus<half,half>::type one;
|
|
typedef <a href="../Reference/rational_c.html">rational_c</a><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;
|
|
</pre>
|
|
<p>
|
|
<h3>See also</h3>
|
|
<p>
|
|
<a href="../Rational_Constant.html">Rational Constant</a>, <a href="../Integral_Constant.html">Integral Constant</a>, <code>integral_c</code>
|
|
<p><hr>
|
|
<a href="../Table_of_Contents.html">Table of Contents</a><br>Last edited October 30, 2003 2:44 am</body></html> |