boost/doc/html/ratio/appendices.html
2021-10-05 21:37:46 +02:00

1599 lines
74 KiB
HTML
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Appendices</title>
<link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
<link rel="up" href="../ratio.html" title="Chapter 35. Boost.Ratio 2.1.0">
<link rel="prev" href="reference.html" title="Reference">
<link rel="next" href="../signals2.html" title="Chapter 36. Boost.Signals2">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
<td align="center"><a href="../../../index.html">Home</a></td>
<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="reference.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../ratio.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../signals2.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="ratio.appendices"></a><a class="link" href="appendices.html" title="Appendices">Appendices</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="appendices.html#ratio.appendices.history">Appendix A: History</a></span></dt>
<dt><span class="section"><a href="appendices.html#ratio.appendices.rationale">Appendix B: Rationale</a></span></dt>
<dt><span class="section"><a href="appendices.html#ratio.appendices.implementation">Appendix C: Implementation
Notes</a></span></dt>
<dt><span class="section"><a href="appendices.html#ratio.appendices.faq">Appendix D: FAQ</a></span></dt>
<dt><span class="section"><a href="appendices.html#ratio.appendices.acknowledgements">Appendix E: Acknowledgements</a></span></dt>
<dt><span class="section"><a href="appendices.html#ratio.appendices.tests">Appendix F: Tests</a></span></dt>
<dt><span class="section"><a href="appendices.html#ratio.appendices.tickets">Appendix G: Tickets</a></span></dt>
<dt><span class="section"><a href="appendices.html#ratio.appendices.todo">Appendix H: Future Plans</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="ratio.appendices.history"></a><a class="link" href="appendices.html#ratio.appendices.history" title="Appendix A: History">Appendix A: History</a>
</h3></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="appendices.html#ratio.appendices.history.__version_2_1_0__febreary_1__2014___1_56__"><span class="bold"><strong>Version 2.1.0, Febreary 1, 2014 - 1.56</strong></span> </a></span></dt>
<dt><span class="section"><a href="appendices.html#ratio.appendices.history.__version_2_0_1__febreary_1__2013___1_53__"><span class="bold"><strong>Version 2.0.1, Febreary 1, 2013 - 1.53</strong></span> </a></span></dt>
<dt><span class="section"><a href="appendices.html#ratio.appendices.history.__version_2_0_0__november_1__2012___1_52__"><span class="bold"><strong>Version 2.0.0, November 1, 2012 - 1.52</strong></span> </a></span></dt>
<dt><span class="section"><a href="appendices.html#ratio.appendices.history.__version_1_0_3__august_1__2012___1_51__"><span class="bold"><strong>Version 1.0.3, August 1, 2012 - 1.51</strong></span> </a></span></dt>
<dt><span class="section"><a href="appendices.html#ratio.appendices.history.__version_1_0_2__april_1__2012___1_50__"><span class="bold"><strong>Version 1.0.2, April 1, 2012 - 1.50</strong></span> </a></span></dt>
<dt><span class="section"><a href="appendices.html#ratio.appendices.history.__version_1_0_1__jan_8__2011___"><span class="bold"><strong>Version 1.0.1, Jan 8, 2011 </strong></span> </a></span></dt>
<dt><span class="section"><a href="appendices.html#ratio.appendices.history.__version_1_0_0__jan_2__2011__"><span class="bold"><strong>Version 1.0.0, Jan 2, 2011</strong></span> </a></span></dt>
<dt><span class="section"><a href="appendices.html#ratio.appendices.history.__version_0_2_1__september_27__2010__"><span class="bold"><strong>Version 0.2.1, September 27, 2010</strong></span> </a></span></dt>
<dt><span class="section"><a href="appendices.html#ratio.appendices.history.__version_0_2_0__september_22__2010__"><span class="bold"><strong>Version 0.2.0, September 22, 2010</strong></span> </a></span></dt>
<dt><span class="section"><a href="appendices.html#ratio.appendices.history.__version_0_1_0__september_10__2010__"><span class="bold"><strong>Version 0.1.0, September 10, 2010</strong></span> </a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="ratio.appendices.history.__version_2_1_0__febreary_1__2014___1_56__"></a><a class="link" href="appendices.html#ratio.appendices.history.__version_2_1_0__febreary_1__2014___1_56__" title="Version 2.1.0, Febreary 1, 2014 - 1.56"><span class="bold"><strong>Version 2.1.0, Febreary 1, 2014 - 1.56</strong></span> </a>
</h4></div></div></div>
<p>
<span class="bold"><strong>New Features:</strong></span>
</p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<a href="http://svn.boost.org/trac/boost/ticket/XXXX" target="_top">#XXXX</a>
Add ratio_power.
</li>
<li class="listitem">
<a href="http://svn.boost.org/trac/boost/ticket/XXXX" target="_top">#XXXX</a>
Add IEC binary prefixes.
</li>
</ul></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="ratio.appendices.history.__version_2_0_1__febreary_1__2013___1_53__"></a><a class="link" href="appendices.html#ratio.appendices.history.__version_2_0_1__febreary_1__2013___1_53__" title="Version 2.0.1, Febreary 1, 2013 - 1.53"><span class="bold"><strong>Version 2.0.1, Febreary 1, 2013 - 1.53</strong></span> </a>
</h4></div></div></div>
<p>
<span class="bold"><strong>Fixes:</strong></span>
</p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
<a href="http://svn.boost.org/trac/boost/ticket/7616" target="_top">#7616</a>
br_mul::nan - warning C4293: '&lt;&lt;' : shift count negative or too
big, undefined behavior`.
</li></ul></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="ratio.appendices.history.__version_2_0_0__november_1__2012___1_52__"></a><a class="link" href="appendices.html#ratio.appendices.history.__version_2_0_0__november_1__2012___1_52__" title="Version 2.0.0, November 1, 2012 - 1.52"><span class="bold"><strong>Version 2.0.0, November 1, 2012 - 1.52</strong></span> </a>
</h4></div></div></div>
<p>
<span class="bold"><strong>Features:</strong></span>
</p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
Replace the short_name and long_name functions by symbol and prefix
functions respectively.
</li></ul></div>
<p>
<span class="bold"><strong>Deprecated:</strong></span>
</p>
<p>
The ratio_string&lt;&gt;::short_name and ratio_string&lt;&gt;::long_name
are deprecated. Use ratio_string&lt;&gt;::symbol and ratio_string&lt;&gt;::prefix
respectively. These functions be removed in 1.55.
</p>
<p>
<span class="bold"><strong>Fixes:</strong></span>
</p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
<a href="http://svn.boost.org/trac/boost/ticket/7478" target="_top">#7478</a>
Compiles fails with compilers supporting char16_t and char32_t fails
if the library doesn't provides std::u16string and std::u32string.
</li></ul></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="ratio.appendices.history.__version_1_0_3__august_1__2012___1_51__"></a><a class="link" href="appendices.html#ratio.appendices.history.__version_1_0_3__august_1__2012___1_51__" title="Version 1.0.3, August 1, 2012 - 1.51"><span class="bold"><strong>Version 1.0.3, August 1, 2012 - 1.51</strong></span> </a>
</h4></div></div></div>
<p>
<span class="bold"><strong>Fixes:</strong></span>
</p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
<a href="http://svn.boost.org/trac/boost/ticket/7075" target="_top">#7075</a>
Workaround for error: the type of partial specialization template parameter
constant "n1" depends on another template parameter.
</li></ul></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="ratio.appendices.history.__version_1_0_2__april_1__2012___1_50__"></a><a class="link" href="appendices.html#ratio.appendices.history.__version_1_0_2__april_1__2012___1_50__" title="Version 1.0.2, April 1, 2012 - 1.50"><span class="bold"><strong>Version 1.0.2, April 1, 2012 - 1.50</strong></span> </a>
</h4></div></div></div>
<p>
<span class="bold"><strong>Fixes:</strong></span>
</p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
<a href="http://svn.boost.org/trac/boost/ticket/6498" target="_top">#6498</a>
boost::ratio won't compile with default settings.
</li></ul></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="ratio.appendices.history.__version_1_0_1__jan_8__2011___"></a><a class="link" href="appendices.html#ratio.appendices.history.__version_1_0_1__jan_8__2011___" title="Version 1.0.1, Jan 8, 2011"><span class="bold"><strong>Version 1.0.1, Jan 8, 2011 </strong></span> </a>
</h4></div></div></div>
<p>
<span class="bold"><strong>Features:</strong></span>
</p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
Added MPL Rational Constant and the associated numeric metafunction
specializations.
</li></ul></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="ratio.appendices.history.__version_1_0_0__jan_2__2011__"></a><a class="link" href="appendices.html#ratio.appendices.history.__version_1_0_0__jan_2__2011__" title="Version 1.0.0, Jan 2, 2011"><span class="bold"><strong>Version 1.0.0, Jan 2, 2011</strong></span> </a>
</h4></div></div></div>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
Moved ratio to trunk.
</li>
<li class="listitem">
Documentation revision.
</li>
</ul></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="ratio.appendices.history.__version_0_2_1__september_27__2010__"></a><a class="link" href="appendices.html#ratio.appendices.history.__version_0_2_1__september_27__2010__" title="Version 0.2.1, September 27, 2010"><span class="bold"><strong>Version 0.2.1, September 27, 2010</strong></span> </a>
</h4></div></div></div>
<p>
<span class="bold"><strong>Fixes:</strong></span>
</p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
Removal of LLVM adapted files due to incompatible License issue.
</li></ul></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="ratio.appendices.history.__version_0_2_0__september_22__2010__"></a><a class="link" href="appendices.html#ratio.appendices.history.__version_0_2_0__september_22__2010__" title="Version 0.2.0, September 22, 2010"><span class="bold"><strong>Version 0.2.0, September 22, 2010</strong></span> </a>
</h4></div></div></div>
<p>
<span class="bold"><strong>Features:</strong></span>
</p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
Added ratio_string traits.
</li></ul></div>
<p>
<span class="bold"><strong>Fixes:</strong></span>
</p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
ratio_less overflow avoided following the algorithm from libc++.
</li></ul></div>
<p>
<span class="bold"><strong>Test:</strong></span>
</p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
A more complete test has been included adapted from the test of from
libc++/ratio.
</li></ul></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="ratio.appendices.history.__version_0_1_0__september_10__2010__"></a><a class="link" href="appendices.html#ratio.appendices.history.__version_0_1_0__september_10__2010__" title="Version 0.1.0, September 10, 2010"><span class="bold"><strong>Version 0.1.0, September 10, 2010</strong></span> </a>
</h4></div></div></div>
<p>
<span class="bold"><strong>Features:</strong></span>
</p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
Ratio has been extracted from Boost.Chrono.
</li></ul></div>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="ratio.appendices.rationale"></a><a class="link" href="appendices.html#ratio.appendices.rationale" title="Appendix B: Rationale">Appendix B: Rationale</a>
</h3></div></div></div>
<h5>
<a name="ratio.appendices.rationale.h0"></a>
<span class="phrase"><a name="ratio.appendices.rationale.why_ratio_needs_copyconstruction_and_assignment_from_ratios_having_the_same_normalized_form"></a></span><a class="link" href="appendices.html#ratio.appendices.rationale.why_ratio_needs_copyconstruction_and_assignment_from_ratios_having_the_same_normalized_form">Why
ratio needs CopyConstruction and Assignment from ratios having the same normalized
form</a>
</h5>
<p>
Current <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n3000.pdf" target="_top"><span class="bold"><strong>N3000</strong></span></a> doesn't allows to copy-construct or
assign ratio instances of ratio classes having the same normalized form.
</p>
<p>
This simple example
</p>
<pre class="programlisting"><a class="link" href="reference.html#ratio.reference.std.ratio_hpp.ratio" title="Class Template ratio&lt;&gt;"><code class="computeroutput"><span class="identifier">ratio</span></code></a><span class="special">&lt;</span><span class="number">1</span><span class="special">,</span><span class="number">3</span><span class="special">&gt;</span> <span class="identifier">r1</span><span class="special">;</span>
<a class="link" href="reference.html#ratio.reference.std.ratio_hpp.ratio" title="Class Template ratio&lt;&gt;"><code class="computeroutput"><span class="identifier">ratio</span></code></a><span class="special">&lt;</span><span class="number">3</span><span class="special">,</span><span class="number">9</span><span class="special">&gt;</span> <span class="identifier">r2</span><span class="special">;</span>
<span class="identifier">r1</span> <span class="special">=</span> <span class="identifier">r2</span><span class="special">;</span> <span class="comment">// (1)</span>
</pre>
<p>
fails to compile in (1). Other example
</p>
<pre class="programlisting"><a class="link" href="reference.html#ratio.reference.std.ratio_hpp.ratio" title="Class Template ratio&lt;&gt;"><code class="computeroutput"><span class="identifier">ratio</span></code></a><span class="special">&lt;</span><span class="number">1</span><span class="special">,</span><span class="number">3</span><span class="special">&gt;</span> <span class="identifier">r1</span><span class="special">;</span>
<a class="link" href="reference.html#ratio.reference.std.ratio_hpp.ratio_arithmetic" title="ratio Arithmetic"><code class="computeroutput"><span class="identifier">ratio_subtract</span></code></a><span class="special">&lt;</span><a class="link" href="reference.html#ratio.reference.std.ratio_hpp.ratio" title="Class Template ratio&lt;&gt;"><code class="computeroutput"><span class="identifier">ratio</span></code></a><span class="special">&lt;</span><span class="number">2</span><span class="special">,</span><span class="number">3</span><span class="special">&gt;,</span><a class="link" href="reference.html#ratio.reference.std.ratio_hpp.ratio" title="Class Template ratio&lt;&gt;"><code class="computeroutput"><span class="identifier">ratio</span></code></a><span class="special">&lt;</span><span class="number">1</span><span class="special">,</span><span class="number">3</span><span class="special">&gt;</span> <span class="special">&gt;</span> <span class="identifier">r2</span><span class="special">=</span><span class="identifier">r1</span><span class="special">;</span> <span class="comment">// (2)</span>
</pre>
<p>
The type of <code class="computeroutput"><a class="link" href="reference.html#ratio.reference.std.ratio_hpp.ratio_arithmetic" title="ratio Arithmetic"><code class="computeroutput"><span class="identifier">ratio_subtract</span></code></a><span class="special">&lt;</span><a class="link" href="reference.html#ratio.reference.std.ratio_hpp.ratio" title="Class Template ratio&lt;&gt;"><code class="computeroutput"><span class="identifier">ratio</span></code></a><span class="special">&lt;</span><span class="number">2</span><span class="special">,</span><span class="number">3</span><span class="special">&gt;,</span><a class="link" href="reference.html#ratio.reference.std.ratio_hpp.ratio" title="Class Template ratio&lt;&gt;"><code class="computeroutput"><span class="identifier">ratio</span></code></a><span class="special">&lt;</span><span class="number">1</span><span class="special">,</span><span class="number">3</span><span class="special">&gt;</span> <span class="special">&gt;</span></code>
could be <code class="computeroutput"><a class="link" href="reference.html#ratio.reference.std.ratio_hpp.ratio" title="Class Template ratio&lt;&gt;"><code class="computeroutput"><span class="identifier">ratio</span></code></a><span class="special">&lt;</span><span class="number">3</span><span class="special">,</span><span class="number">9</span><span class="special">&gt;</span></code> so the compilation could fail in (2).
It could also be <a class="link" href="reference.html#ratio.reference.std.ratio_hpp.ratio" title="Class Template ratio&lt;&gt;"><code class="computeroutput"><span class="identifier">ratio</span></code></a>&lt;1,3&gt; and the compilation
succeeds.
</p>
<h5>
<a name="ratio.appendices.rationale.h1"></a>
<span class="phrase"><a name="ratio.appendices.rationale.why_ratio_needs_the_nested_normalizer_typedef_type"></a></span><a class="link" href="appendices.html#ratio.appendices.rationale.why_ratio_needs_the_nested_normalizer_typedef_type">Why
ratio needs the nested normalizer typedef type</a>
</h5>
<p>
The current resolution of issue LWG 1281 acknowledges the need for a nested
type typedef, so Boost.Ratio is tracking the likely final version of std::ratio.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="ratio.appendices.implementation"></a><a class="link" href="appendices.html#ratio.appendices.implementation" title="Appendix C: Implementation Notes">Appendix C: Implementation
Notes</a>
</h3></div></div></div>
<h5>
<a name="ratio.appendices.implementation.h0"></a>
<span class="phrase"><a name="ratio.appendices.implementation.how_does_boost_ratio_try_to_avoid_compile_time_rational_arithmetic_overflow_"></a></span><a class="link" href="appendices.html#ratio.appendices.implementation.how_does_boost_ratio_try_to_avoid_compile_time_rational_arithmetic_overflow_">How
does Boost.Ratio try to avoid compile-time rational arithmetic overflow?</a>
</h5>
<p>
When the result is representable, but a simple application of arithmetic
rules would result in overflow, e.g. <code class="computeroutput"><span class="identifier">ratio_multiply</span><span class="special">&lt;</span><span class="identifier">ratio</span><span class="special">&lt;</span><span class="identifier">INTMAX_MAX</span><span class="special">,</span><span class="number">2</span><span class="special">&gt;,</span><span class="identifier">ratio</span><span class="special">&lt;</span><span class="number">2</span><span class="special">,</span><span class="identifier">INTMAX_MAX</span><span class="special">&gt;&gt;</span></code> can be reduced to <code class="computeroutput"><span class="identifier">ratio</span><span class="special">&lt;</span><span class="number">1</span><span class="special">,</span><span class="number">1</span><span class="special">&gt;</span></code>, but
the direct result of <code class="computeroutput"><span class="identifier">ratio</span><span class="special">&lt;</span><span class="identifier">INTMAX_MAX</span><span class="special">*</span><span class="number">2</span><span class="special">,</span><span class="identifier">INTMAX_MAX</span><span class="special">*</span><span class="number">2</span><span class="special">&gt;</span></code> would
result in overflow.
</p>
<p>
Boost.Ratio implements some simplifications in order to reduce the possibility
of overflow. The general ideas are:
</p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
The <code class="computeroutput"><span class="identifier">num</span></code> and <code class="computeroutput"><span class="identifier">den</span></code> <code class="computeroutput"><span class="identifier">ratio</span><span class="special">&lt;&gt;</span></code> fields are normalized.
</li>
<li class="listitem">
Use the gcd of some of the possible products that can overflow, and simplify
before doing the product.
</li>
<li class="listitem">
Use some equivalences relations that avoid addition or subtraction that
can overflow or underflow.
</li>
</ul></div>
<p>
The following subsections cover each case in more detail.
</p>
<p>
<span class="bold"><strong>ratio_add</strong></span>
</p>
<p>
In
</p>
<pre class="programlisting"><span class="special">(</span><span class="identifier">n1</span><span class="special">/</span><span class="identifier">d1</span><span class="special">)+(</span><span class="identifier">n2</span><span class="special">/</span><span class="identifier">d2</span><span class="special">)=(</span><span class="identifier">n1</span><span class="special">*</span><span class="identifier">d2</span><span class="special">+</span><span class="identifier">n2</span><span class="special">*</span><span class="identifier">d1</span><span class="special">)/(</span><span class="identifier">d1</span><span class="special">*</span><span class="identifier">d2</span><span class="special">)</span>
</pre>
<p>
either n1*d2+n2*d1 or d1*d2 can overflow.
</p>
<pre class="programlisting"><span class="special">(</span> <span class="special">(</span><span class="identifier">n1</span> <span class="special">*</span> <span class="identifier">d2</span><span class="special">)</span> <span class="special">+</span> <span class="special">(</span><span class="identifier">n2</span> <span class="special">*</span> <span class="identifier">d1</span><span class="special">)</span> <span class="special">)</span>
<span class="special">--------------------------</span>
<span class="special">(</span><span class="identifier">d1</span> <span class="special">*</span> <span class="identifier">d2</span><span class="special">)</span>
</pre>
<p>
Dividing by gcd(d1,d2) on both num and den
</p>
<pre class="programlisting"><span class="special">(</span> <span class="special">(</span><span class="identifier">n1</span> <span class="special">*</span> <span class="special">(</span><span class="identifier">d2</span><span class="special">/</span><span class="identifier">gcd</span><span class="special">(</span><span class="identifier">d1</span><span class="special">,</span><span class="identifier">d2</span><span class="special">)))</span> <span class="special">+</span> <span class="special">(</span><span class="identifier">n2</span> <span class="special">*</span> <span class="special">(</span><span class="identifier">d1</span><span class="special">/</span><span class="identifier">gcd</span><span class="special">(</span><span class="identifier">d1</span><span class="special">,</span><span class="identifier">d2</span><span class="special">)))</span> <span class="special">)</span>
<span class="special">----------------------------------------------------</span>
<span class="special">((</span><span class="identifier">d1</span> <span class="special">*</span> <span class="identifier">d2</span><span class="special">)</span> <span class="special">/</span> <span class="identifier">gcd</span><span class="special">(</span><span class="identifier">d1</span><span class="special">,</span><span class="identifier">d2</span><span class="special">))</span>
</pre>
<p>
Multiplying and diving by gcd(n1,n2) in numerator
</p>
<pre class="programlisting"><span class="special">(</span> <span class="special">((</span><span class="identifier">gcd</span><span class="special">(</span><span class="identifier">n1</span><span class="special">,</span><span class="identifier">n2</span><span class="special">)*(</span><span class="identifier">n1</span><span class="special">/</span><span class="identifier">gcd</span><span class="special">(</span><span class="identifier">n1</span><span class="special">,</span><span class="identifier">n2</span><span class="special">)))</span> <span class="special">*</span> <span class="special">(</span><span class="identifier">d2</span><span class="special">/</span><span class="identifier">gcd</span><span class="special">(</span><span class="identifier">d1</span><span class="special">,</span><span class="identifier">d2</span><span class="special">)))</span> <span class="special">+</span>
<span class="special">((</span><span class="identifier">gcd</span><span class="special">(</span><span class="identifier">n1</span><span class="special">,</span><span class="identifier">n2</span><span class="special">)*(</span><span class="identifier">n2</span><span class="special">/</span><span class="identifier">gcd</span><span class="special">(</span><span class="identifier">n1</span><span class="special">,</span><span class="identifier">n2</span><span class="special">)))</span> <span class="special">*</span> <span class="special">(</span><span class="identifier">d1</span><span class="special">/</span><span class="identifier">gcd</span><span class="special">(</span><span class="identifier">d1</span><span class="special">,</span><span class="identifier">d2</span><span class="special">)))</span>
<span class="special">)</span>
<span class="special">--------------------------------------------------</span>
<span class="special">(</span> <span class="special">(</span><span class="identifier">d1</span> <span class="special">*</span> <span class="identifier">d2</span><span class="special">)</span> <span class="special">/</span> <span class="identifier">gcd</span><span class="special">(</span><span class="identifier">d1</span><span class="special">,</span><span class="identifier">d2</span><span class="special">)</span> <span class="special">)</span>
</pre>
<p>
Factorizing gcd(n1,n2)
</p>
<pre class="programlisting"><span class="special">(</span> <span class="identifier">gcd</span><span class="special">(</span><span class="identifier">n1</span><span class="special">,</span><span class="identifier">n2</span><span class="special">)</span> <span class="special">*</span>
<span class="special">(</span> <span class="special">((</span><span class="identifier">n1</span><span class="special">/</span><span class="identifier">gcd</span><span class="special">(</span><span class="identifier">n1</span><span class="special">,</span><span class="identifier">n2</span><span class="special">))</span> <span class="special">*</span> <span class="special">(</span><span class="identifier">d2</span><span class="special">/</span><span class="identifier">gcd</span><span class="special">(</span><span class="identifier">d1</span><span class="special">,</span><span class="identifier">d2</span><span class="special">)))</span> <span class="special">+</span> <span class="special">((</span><span class="identifier">n2</span><span class="special">/</span><span class="identifier">gcd</span><span class="special">(</span><span class="identifier">n1</span><span class="special">,</span><span class="identifier">n2</span><span class="special">))</span> <span class="special">*</span> <span class="special">(</span><span class="identifier">d1</span><span class="special">/</span><span class="identifier">gcd</span><span class="special">(</span><span class="identifier">d1</span><span class="special">,</span><span class="identifier">d2</span><span class="special">)))</span> <span class="special">)</span>
<span class="special">)</span>
<span class="special">-------------------------------------------------------------------------------</span>
<span class="special">(</span> <span class="special">(</span><span class="identifier">d1</span> <span class="special">*</span> <span class="identifier">d2</span><span class="special">)</span> <span class="special">/</span> <span class="identifier">gcd</span><span class="special">(</span><span class="identifier">d1</span><span class="special">,</span><span class="identifier">d2</span><span class="special">)</span> <span class="special">)</span>
</pre>
<p>
Regrouping
</p>
<pre class="programlisting"><span class="special">(</span> <span class="identifier">gcd</span><span class="special">(</span><span class="identifier">n1</span><span class="special">,</span><span class="identifier">n2</span><span class="special">)</span> <span class="special">*</span>
<span class="special">(</span> <span class="special">((</span><span class="identifier">n1</span><span class="special">/</span><span class="identifier">gcd</span><span class="special">(</span><span class="identifier">n1</span><span class="special">,</span><span class="identifier">n2</span><span class="special">))</span> <span class="special">*</span> <span class="special">(</span><span class="identifier">d2</span><span class="special">/</span><span class="identifier">gcd</span><span class="special">(</span><span class="identifier">d1</span><span class="special">,</span><span class="identifier">d2</span><span class="special">)))</span> <span class="special">+</span> <span class="special">((</span><span class="identifier">n2</span><span class="special">/</span><span class="identifier">gcd</span><span class="special">(</span><span class="identifier">n1</span><span class="special">,</span><span class="identifier">n2</span><span class="special">))</span> <span class="special">*</span> <span class="special">(</span><span class="identifier">d1</span><span class="special">/</span><span class="identifier">gcd</span><span class="special">(</span><span class="identifier">d1</span><span class="special">,</span><span class="identifier">d2</span><span class="special">)))</span> <span class="special">)</span>
<span class="special">)</span>
<span class="special">-------------------------------------------------------------------------------</span>
<span class="special">(</span> <span class="special">(</span><span class="identifier">d1</span> <span class="special">/</span> <span class="identifier">gcd</span><span class="special">(</span><span class="identifier">d1</span><span class="special">,</span><span class="identifier">d2</span><span class="special">))</span> <span class="special">*</span> <span class="identifier">d2</span> <span class="special">)</span>
</pre>
<p>
Dividing by (d1 / gcd(d1,d2))
</p>
<pre class="programlisting"><span class="special">(</span> <span class="special">(</span> <span class="identifier">gcd</span><span class="special">(</span><span class="identifier">n1</span><span class="special">,</span><span class="identifier">n2</span><span class="special">)</span> <span class="special">/</span> <span class="special">(</span><span class="identifier">d1</span> <span class="special">/</span> <span class="identifier">gcd</span><span class="special">(</span><span class="identifier">d1</span><span class="special">,</span><span class="identifier">d2</span><span class="special">))</span> <span class="special">)</span> <span class="special">*</span>
<span class="special">(</span> <span class="special">((</span><span class="identifier">n1</span><span class="special">/</span><span class="identifier">gcd</span><span class="special">(</span><span class="identifier">n1</span><span class="special">,</span><span class="identifier">n2</span><span class="special">))</span> <span class="special">*</span> <span class="special">(</span><span class="identifier">d2</span><span class="special">/</span><span class="identifier">gcd</span><span class="special">(</span><span class="identifier">d1</span><span class="special">,</span><span class="identifier">d2</span><span class="special">)))</span> <span class="special">+</span> <span class="special">((</span><span class="identifier">n2</span><span class="special">/</span><span class="identifier">gcd</span><span class="special">(</span><span class="identifier">n1</span><span class="special">,</span><span class="identifier">n2</span><span class="special">))</span> <span class="special">*</span> <span class="special">(</span><span class="identifier">d1</span><span class="special">/</span><span class="identifier">gcd</span><span class="special">(</span><span class="identifier">d1</span><span class="special">,</span><span class="identifier">d2</span><span class="special">)))</span> <span class="special">)</span>
<span class="special">)</span>
<span class="special">-------------------------------------------------------------------------------</span>
<span class="identifier">d2</span>
</pre>
<p>
Dividing by d2
</p>
<pre class="programlisting"><span class="special">(</span> <span class="identifier">gcd</span><span class="special">(</span><span class="identifier">n1</span><span class="special">,</span><span class="identifier">n2</span><span class="special">)</span> <span class="special">/</span> <span class="special">(</span><span class="identifier">d1</span> <span class="special">/</span> <span class="identifier">gcd</span><span class="special">(</span><span class="identifier">d1</span><span class="special">,</span><span class="identifier">d2</span><span class="special">))</span> <span class="special">)</span> <span class="special">*</span>
<span class="special">(</span> <span class="special">((</span><span class="identifier">n1</span><span class="special">/</span><span class="identifier">gcd</span><span class="special">(</span><span class="identifier">n1</span><span class="special">,</span><span class="identifier">n2</span><span class="special">))</span> <span class="special">*</span> <span class="special">(</span><span class="identifier">d2</span><span class="special">/</span><span class="identifier">gcd</span><span class="special">(</span><span class="identifier">d1</span><span class="special">,</span><span class="identifier">d2</span><span class="special">)))</span> <span class="special">+</span> <span class="special">((</span><span class="identifier">n2</span><span class="special">/</span><span class="identifier">gcd</span><span class="special">(</span><span class="identifier">n1</span><span class="special">,</span><span class="identifier">n2</span><span class="special">))</span> <span class="special">*</span> <span class="special">(</span><span class="identifier">d1</span><span class="special">/</span><span class="identifier">gcd</span><span class="special">(</span><span class="identifier">d1</span><span class="special">,</span><span class="identifier">d2</span><span class="special">)))</span> <span class="special">/</span> <span class="identifier">d2</span> <span class="special">)</span>
</pre>
<p>
This expression correspond to the multiply of two ratios that have less risk
of overflow as the initial numerators and denominators appear now in most
of the cases divided by a gcd.
</p>
<p>
For ratio_subtract the reasoning is the same.
</p>
<p>
<span class="bold"><strong>ratio_multiply</strong></span>
</p>
<p>
In
</p>
<pre class="programlisting"><span class="special">(</span><span class="identifier">n1</span><span class="special">/</span><span class="identifier">d1</span><span class="special">)*(</span><span class="identifier">n2</span><span class="special">/</span><span class="identifier">d2</span><span class="special">)=((</span><span class="identifier">n1</span><span class="special">*</span><span class="identifier">n2</span><span class="special">)/(</span><span class="identifier">d1</span><span class="special">*</span><span class="identifier">d2</span><span class="special">))</span>
</pre>
<p>
either n1*n2 or d1*d2 can overflow.
</p>
<p>
Dividing by gcc(n1,d2) numerator and denominator
</p>
<pre class="programlisting"><span class="special">(((</span><span class="identifier">n1</span><span class="special">/</span><span class="identifier">gcc</span><span class="special">(</span><span class="identifier">n1</span><span class="special">,</span><span class="identifier">d2</span><span class="special">))*</span><span class="identifier">n2</span><span class="special">)</span>
<span class="special">---------------------</span>
<span class="special">(</span><span class="identifier">d1</span><span class="special">*(</span><span class="identifier">d2</span><span class="special">/</span><span class="identifier">gcc</span><span class="special">(</span><span class="identifier">n1</span><span class="special">,</span><span class="identifier">d2</span><span class="special">))))</span>
</pre>
<p>
Dividing by gcc(n2,d1)
</p>
<pre class="programlisting"><span class="special">((</span><span class="identifier">n1</span><span class="special">/</span><span class="identifier">gcc</span><span class="special">(</span><span class="identifier">n1</span><span class="special">,</span><span class="identifier">d2</span><span class="special">))*(</span><span class="identifier">n2</span><span class="special">/</span><span class="identifier">gcc</span><span class="special">(</span><span class="identifier">n2</span><span class="special">,</span><span class="identifier">d1</span><span class="special">)))</span>
<span class="special">---------------------------------</span>
<span class="special">((</span><span class="identifier">d1</span><span class="special">/</span><span class="identifier">gcc</span><span class="special">(</span><span class="identifier">n2</span><span class="special">,</span><span class="identifier">d1</span><span class="special">))*(</span><span class="identifier">d2</span><span class="special">/</span><span class="identifier">gcc</span><span class="special">(</span><span class="identifier">n1</span><span class="special">,</span><span class="identifier">d2</span><span class="special">)))</span>
</pre>
<p>
And now all the initial numerator and denominators have been reduced, avoiding
the overflow.
</p>
<p>
For ratio_divide the reasoning is similar.
</p>
<p>
<span class="bold"><strong>ratio_less</strong></span>
</p>
<p>
In order to evaluate
</p>
<pre class="programlisting"><span class="special">(</span><span class="identifier">n1</span><span class="special">/</span><span class="identifier">d1</span><span class="special">)&lt;(</span><span class="identifier">n2</span><span class="special">/</span><span class="identifier">d2</span><span class="special">)</span>
</pre>
<p>
without moving to floating-point numbers, two techniques are used:
</p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
First compare the sign of the numerators.
</li></ul></div>
<p>
If sign(n1) &lt; sign(n2) the result is true.
</p>
<p>
If sign(n1) == sign(n2) the result depends on the following after making
the numerators positive
</p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
When the sign is equal the technique used is to work with integer division
and modulo when the signs are equal.
</li></ul></div>
<p>
Let call Qi the integer division of ni and di, and Mi the modulo of ni and
di.
</p>
<pre class="programlisting"><span class="identifier">ni</span> <span class="special">=</span> <span class="identifier">Qi</span> <span class="special">*</span> <span class="identifier">di</span> <span class="special">+</span> <span class="identifier">Mi</span> <span class="keyword">and</span> <span class="identifier">Mi</span> <span class="special">&lt;</span> <span class="identifier">di</span>
</pre>
<p>
Form
</p>
<pre class="programlisting"><span class="special">((</span><span class="identifier">n1</span><span class="special">*</span><span class="identifier">d2</span><span class="special">)&lt;(</span><span class="identifier">d1</span><span class="special">*</span><span class="identifier">n2</span><span class="special">))</span>
</pre>
<p>
we get
</p>
<pre class="programlisting"><span class="special">(((</span><span class="identifier">Q1</span> <span class="special">*</span> <span class="identifier">d1</span> <span class="special">+</span> <span class="identifier">M1</span><span class="special">)*</span><span class="identifier">d2</span><span class="special">)&lt;(</span><span class="identifier">d1</span><span class="special">*((</span><span class="identifier">Q2</span> <span class="special">*</span> <span class="identifier">d2</span> <span class="special">+</span> <span class="identifier">M2</span><span class="special">))))</span>
</pre>
<p>
Developing
</p>
<pre class="programlisting"><span class="special">((</span><span class="identifier">Q1</span> <span class="special">*</span> <span class="identifier">d1</span> <span class="special">*</span> <span class="identifier">d2</span><span class="special">)+</span> <span class="special">(</span><span class="identifier">M1</span><span class="special">*</span><span class="identifier">d2</span><span class="special">))&lt;((</span><span class="identifier">d1</span> <span class="special">*</span> <span class="identifier">Q2</span> <span class="special">*</span> <span class="identifier">d2</span><span class="special">)</span> <span class="special">+</span> <span class="special">(</span><span class="identifier">d1</span><span class="special">*</span><span class="identifier">M2</span><span class="special">))</span>
</pre>
<p>
Dividing by d1*d2
</p>
<pre class="programlisting"><span class="identifier">Q1</span> <span class="special">+</span> <span class="special">(</span><span class="identifier">M1</span><span class="special">/</span><span class="identifier">d1</span><span class="special">)</span> <span class="special">&lt;</span> <span class="identifier">Q2</span> <span class="special">+</span> <span class="special">(</span><span class="identifier">M2</span><span class="special">/</span><span class="identifier">d2</span><span class="special">)</span>
</pre>
<p>
If Q1=Q2 the result depends on
</p>
<pre class="programlisting"><span class="special">(</span><span class="identifier">M1</span><span class="special">/</span><span class="identifier">d1</span><span class="special">)</span> <span class="special">&lt;</span> <span class="special">(</span><span class="identifier">M2</span><span class="special">/</span><span class="identifier">d2</span><span class="special">)</span>
</pre>
<p>
If M1==0==M2 the result is false
</p>
<p>
If M1=0 M2!=0 the result is true
</p>
<p>
If M1!=0 M2==0 the result is false
</p>
<p>
If M1!=0 M2!=0 the result depends on
</p>
<pre class="programlisting"><span class="special">(</span><span class="identifier">d2</span><span class="special">/</span><span class="identifier">M2</span><span class="special">)</span> <span class="special">&lt;</span> <span class="special">(</span><span class="identifier">d1</span><span class="special">/</span><span class="identifier">M1</span><span class="special">)</span>
</pre>
<p>
If Q1!=Q2, the result of
</p>
<pre class="programlisting"><span class="identifier">Q1</span> <span class="special">+</span> <span class="special">(</span><span class="identifier">M1</span><span class="special">/</span><span class="identifier">d1</span><span class="special">)</span> <span class="special">&lt;</span> <span class="identifier">Q2</span> <span class="special">+</span> <span class="special">(</span><span class="identifier">M2</span><span class="special">/</span><span class="identifier">d2</span><span class="special">)</span>
</pre>
<p>
depends only on Q1 and Q2 as Qi are integers and (Mi/di) &lt;1 because Mi&lt;di.
</p>
<p>
if Q1&gt;Q2, Q1==Q2+k, k&gt;=1
</p>
<pre class="programlisting"><span class="identifier">Q2</span><span class="special">+</span><span class="identifier">k</span> <span class="special">+</span> <span class="special">(</span><span class="identifier">M1</span><span class="special">/</span><span class="identifier">d1</span><span class="special">)</span> <span class="special">&lt;</span> <span class="identifier">Q2</span> <span class="special">+</span> <span class="special">(</span><span class="identifier">M2</span><span class="special">/</span><span class="identifier">d2</span><span class="special">)</span>
<span class="identifier">k</span> <span class="special">+</span> <span class="special">(</span><span class="identifier">M1</span><span class="special">/</span><span class="identifier">d1</span><span class="special">)</span> <span class="special">&lt;</span> <span class="special">(</span><span class="identifier">M2</span><span class="special">/</span><span class="identifier">d2</span><span class="special">)</span>
<span class="identifier">k</span> <span class="special">&lt;</span> <span class="special">(</span><span class="identifier">M2</span><span class="special">/</span><span class="identifier">d2</span><span class="special">)</span> <span class="special">-</span> <span class="special">(</span><span class="identifier">M1</span><span class="special">/</span><span class="identifier">d1</span><span class="special">)</span>
</pre>
<p>
but the difference between two numbers between 0 and 1 can not be greater
than 1, so the result is false.
</p>
<p>
if Q2&gt;Q1, Q2==Q1+k, k&gt;=1
</p>
<pre class="programlisting"><span class="identifier">Q1</span> <span class="special">+</span> <span class="special">(</span><span class="identifier">M1</span><span class="special">/</span><span class="identifier">d1</span><span class="special">)</span> <span class="special">&lt;</span> <span class="identifier">Q1</span><span class="special">+</span><span class="identifier">k</span> <span class="special">+</span> <span class="special">(</span><span class="identifier">M2</span><span class="special">/</span><span class="identifier">d2</span><span class="special">)</span>
<span class="special">(</span><span class="identifier">M1</span><span class="special">/</span><span class="identifier">d1</span><span class="special">)</span> <span class="special">&lt;</span> <span class="identifier">k</span> <span class="special">+</span> <span class="special">(</span><span class="identifier">M2</span><span class="special">/</span><span class="identifier">d2</span><span class="special">)</span>
<span class="special">(</span><span class="identifier">M1</span><span class="special">/</span><span class="identifier">d1</span><span class="special">)</span> <span class="special">-</span> <span class="special">(</span><span class="identifier">M2</span><span class="special">/</span><span class="identifier">d2</span><span class="special">)</span> <span class="special">&lt;</span> <span class="identifier">k</span>
</pre>
<p>
which is always true, so the result is true.
</p>
<p>
The following table recapitulates this analisys
</p>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
<col>
<col>
<col>
<col>
<col>
</colgroup>
<thead><tr>
<th>
<p>
ratio&lt;n1,d1&gt;
</p>
</th>
<th>
<p>
ratio&lt;n2,d2&gt;
</p>
</th>
<th>
<p>
Q1
</p>
</th>
<th>
<p>
Q2
</p>
</th>
<th>
<p>
M1
</p>
</th>
<th>
<p>
M2
</p>
</th>
<th>
<p>
Result
</p>
</th>
</tr></thead>
<tbody>
<tr>
<td>
<p>
ratio&lt;n1,d1&gt;
</p>
</td>
<td>
<p>
ratio&lt;n2,d2&gt;
</p>
</td>
<td>
<p>
Q1
</p>
</td>
<td>
<p>
Q2
</p>
</td>
<td>
<p>
!=0
</p>
</td>
<td>
<p>
!=0
</p>
</td>
<td>
<p>
Q1 &lt; Q2
</p>
</td>
</tr>
<tr>
<td>
<p>
ratio&lt;n1,d1&gt;
</p>
</td>
<td>
<p>
ratio&lt;n2,d2&gt;
</p>
</td>
<td>
<p>
Q
</p>
</td>
<td>
<p>
Q
</p>
</td>
<td>
<p>
0
</p>
</td>
<td>
<p>
0
</p>
</td>
<td>
<p>
false
</p>
</td>
</tr>
<tr>
<td>
<p>
ratio&lt;n1,d1&gt;
</p>
</td>
<td>
<p>
ratio&lt;n2,d2&gt;
</p>
</td>
<td>
<p>
Q
</p>
</td>
<td>
<p>
Q
</p>
</td>
<td>
<p>
0
</p>
</td>
<td>
<p>
!=0
</p>
</td>
<td>
<p>
true
</p>
</td>
</tr>
<tr>
<td>
<p>
ratio&lt;n1,d1&gt;
</p>
</td>
<td>
<p>
ratio&lt;n2,d2&gt;
</p>
</td>
<td>
<p>
Q
</p>
</td>
<td>
<p>
Q
</p>
</td>
<td>
<p>
!=0
</p>
</td>
<td>
<p>
0
</p>
</td>
<td>
<p>
false
</p>
</td>
</tr>
<tr>
<td>
<p>
ratio&lt;n1,d1&gt;
</p>
</td>
<td>
<p>
ratio&lt;n2,d2&gt;
</p>
</td>
<td>
<p>
Q
</p>
</td>
<td>
<p>
Q
</p>
</td>
<td>
<p>
!=0
</p>
</td>
<td>
<p>
!=0
</p>
</td>
<td>
<p>
ratio_less&lt;ratio&lt;d2,M2&gt;, ratio&lt;d1/M1&gt;&gt;
</p>
</td>
</tr>
</tbody>
</table></div>
</div>
<div class="section"><div class="titlepage"><div><div><h3 class="title">
<a name="ratio.appendices.faq"></a><a class="link" href="appendices.html#ratio.appendices.faq" title="Appendix D: FAQ">Appendix D: FAQ</a>
</h3></div></div></div></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="ratio.appendices.acknowledgements"></a><a class="link" href="appendices.html#ratio.appendices.acknowledgements" title="Appendix E: Acknowledgements">Appendix E: Acknowledgements</a>
</h3></div></div></div>
<p>
The library code was derived from Howard Hinnant's <code class="computeroutput"><span class="identifier">time2_demo</span></code>
prototype. Many thanks to Howard for making his code available under the
Boost license. The original code was modified by Beman Dawes to conform to
Boost conventions.
</p>
<p>
<code class="computeroutput"><span class="identifier">time2_demo</span></code> contained this
comment:
</p>
<p>
Much thanks to Andrei Alexandrescu, Walter Brown, Peter Dimov, Jeff Garland,
Terry Golubiewski, Daniel Krugler, Anthony Williams.
</p>
<p>
Howard Hinnant, who is the real author of the library, has provided valuable
feedback and suggestions during the development of the library. In particular,
The ratio_io.hpp source has been adapted from the experimental header <code class="computeroutput"><span class="special">&lt;</span><span class="identifier">ratio_io</span><span class="special">&gt;</span></code> from Howard Hinnant.
</p>
<p>
The acceptance review of Boost.Ratio took place between October 2nd and 11th
2010. Many thanks to Anthony Williams, the review manager, and to all the
reviewers: Bruno Santos, Joel Falcou, Robert Stewart, Roland Bock, Tom Tan
and Paul A. Bristol.
</p>
<p>
Thanks to Andrew Chinoff and Paul A. Bristol for his help polishing the documentation.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="ratio.appendices.tests"></a><a class="link" href="appendices.html#ratio.appendices.tests" title="Appendix F: Tests">Appendix F: Tests</a>
</h3></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="appendices.html#ratio.appendices.tests._ratio_"><code class="computeroutput"><span class="identifier">ratio</span></code></a></span></dt>
<dt><span class="section"><a href="appendices.html#ratio.appendices.tests._comparison_"><code class="computeroutput"><span class="identifier">comparison</span></code></a></span></dt>
<dt><span class="section"><a href="appendices.html#ratio.appendices.tests._arithmetic_"><code class="computeroutput"><span class="identifier">arithmetic</span></code></a></span></dt>
</dl></div>
<p>
In order to test you need to run
</p>
<pre class="programlisting"><span class="identifier">bjam</span> <span class="identifier">libs</span><span class="special">/</span><span class="identifier">ratio</span><span class="special">/</span><span class="identifier">test</span>
</pre>
<p>
You can also run a specific suite of test by doing
</p>
<pre class="programlisting"><span class="identifier">cd</span> <span class="identifier">libs</span><span class="special">/</span><span class="identifier">chrono</span><span class="special">/</span><span class="identifier">test</span>
<span class="identifier">bjam</span> <span class="identifier">ratio</span>
</pre>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="ratio.appendices.tests._ratio_"></a><a class="link" href="appendices.html#ratio.appendices.tests._ratio_" title="ratio"><code class="computeroutput"><span class="identifier">ratio</span></code></a>
</h4></div></div></div>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
<col>
<col>
<col>
</colgroup>
<thead><tr>
<th>
<p>
Name
</p>
</th>
<th>
<p>
kind
</p>
</th>
<th>
<p>
Description
</p>
</th>
<th>
<p>
Result
</p>
</th>
<th>
<p>
Ticket
</p>
</th>
</tr></thead>
<tbody>
<tr>
<td>
<p>
typedefs.pass
</p>
</td>
<td>
<p>
run
</p>
</td>
<td>
<p>
check the num/den are correct for the predefined typedefs
</p>
</td>
<td>
<p>
Pass
</p>
</td>
<td>
<p>
#
</p>
</td>
</tr>
<tr>
<td>
<p>
ratio.pass
</p>
</td>
<td>
<p>
run
</p>
</td>
<td>
<p>
check the num/den are correctly simplified
</p>
</td>
<td>
<p>
Pass
</p>
</td>
<td>
<p>
#
</p>
</td>
</tr>
<tr>
<td>
<p>
ratio1.fail
</p>
</td>
<td>
<p>
compile-fails
</p>
</td>
<td>
<p>
The template argument D shall not be zero
</p>
</td>
<td>
<p>
Pass
</p>
</td>
<td>
<p>
#
</p>
</td>
</tr>
<tr>
<td>
<p>
ratio2.fail
</p>
</td>
<td>
<p>
compile-fails
</p>
</td>
<td>
<p>
the absolute values of the template arguments N and D shall be
representable by type intmax_t
</p>
</td>
<td>
<p>
Pass
</p>
</td>
<td>
<p>
#
</p>
</td>
</tr>
<tr>
<td>
<p>
ratio3.fail
</p>
</td>
<td>
<p>
compile-fails
</p>
</td>
<td>
<p>
the absolute values of the template arguments N and D shall be
representable by type intmax_t
</p>
</td>
<td>
<p>
Pass
</p>
</td>
<td>
<p>
#
</p>
</td>
</tr>
</tbody>
</table></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="ratio.appendices.tests._comparison_"></a><a class="link" href="appendices.html#ratio.appendices.tests._comparison_" title="comparison"><code class="computeroutput"><span class="identifier">comparison</span></code></a>
</h4></div></div></div>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
<col>
<col>
<col>
</colgroup>
<thead><tr>
<th>
<p>
Name
</p>
</th>
<th>
<p>
kind
</p>
</th>
<th>
<p>
Description
</p>
</th>
<th>
<p>
Result
</p>
</th>
<th>
<p>
Ticket
</p>
</th>
</tr></thead>
<tbody>
<tr>
<td>
<p>
ratio_equal.pass
</p>
</td>
<td>
<p>
run
</p>
</td>
<td>
<p>
check ratio_equal metafunction class
</p>
</td>
<td>
<p>
Pass
</p>
</td>
<td>
<p>
#
</p>
</td>
</tr>
<tr>
<td>
<p>
ratio_not_equal.pass
</p>
</td>
<td>
<p>
run
</p>
</td>
<td>
<p>
check ratio_not_equal metafunction class
</p>
</td>
<td>
<p>
Pass
</p>
</td>
<td>
<p>
#
</p>
</td>
</tr>
<tr>
<td>
<p>
ratio_less.pass
</p>
</td>
<td>
<p>
run
</p>
</td>
<td>
<p>
check ratio_less metafunction class
</p>
</td>
<td>
<p>
Pass
</p>
</td>
<td>
<p>
#
</p>
</td>
</tr>
<tr>
<td>
<p>
ratio_less_equal.pass
</p>
</td>
<td>
<p>
run
</p>
</td>
<td>
<p>
check ratio_less_equal metafunction class
</p>
</td>
<td>
<p>
Pass
</p>
</td>
<td>
<p>
#
</p>
</td>
</tr>
<tr>
<td>
<p>
ratio_greater.pass
</p>
</td>
<td>
<p>
run
</p>
</td>
<td>
<p>
check ratio_greater metafunction class
</p>
</td>
<td>
<p>
Pass
</p>
</td>
<td>
<p>
#
</p>
</td>
</tr>
<tr>
<td>
<p>
ratio_greater_equal.pass
</p>
</td>
<td>
<p>
run
</p>
</td>
<td>
<p>
check ratio_greater_equal metafunction class
</p>
</td>
<td>
<p>
Pass
</p>
</td>
<td>
<p>
#
</p>
</td>
</tr>
</tbody>
</table></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="ratio.appendices.tests._arithmetic_"></a><a class="link" href="appendices.html#ratio.appendices.tests._arithmetic_" title="arithmetic"><code class="computeroutput"><span class="identifier">arithmetic</span></code></a>
</h4></div></div></div>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
<col>
<col>
<col>
</colgroup>
<thead><tr>
<th>
<p>
Name
</p>
</th>
<th>
<p>
kind
</p>
</th>
<th>
<p>
Description
</p>
</th>
<th>
<p>
Result
</p>
</th>
<th>
<p>
Ticket
</p>
</th>
</tr></thead>
<tbody>
<tr>
<td>
<p>
ratio_add.pass
</p>
</td>
<td>
<p>
run
</p>
</td>
<td>
<p>
check ratio_add metafunction class
</p>
</td>
<td>
<p>
Pass
</p>
</td>
<td>
<p>
#
</p>
</td>
</tr>
<tr>
<td>
<p>
ratio_subtract.pass
</p>
</td>
<td>
<p>
run
</p>
</td>
<td>
<p>
check ratio_subtract metafunction class
</p>
</td>
<td>
<p>
Pass
</p>
</td>
<td>
<p>
#
</p>
</td>
</tr>
<tr>
<td>
<p>
ratio_multiply.pass
</p>
</td>
<td>
<p>
run
</p>
</td>
<td>
<p>
check ratio_multiply metafunction class
</p>
</td>
<td>
<p>
Pass
</p>
</td>
<td>
<p>
#
</p>
</td>
</tr>
<tr>
<td>
<p>
ratio_divide.pass
</p>
</td>
<td>
<p>
run
</p>
</td>
<td>
<p>
check ratio_divide metafunction class
</p>
</td>
<td>
<p>
Pass
</p>
</td>
<td>
<p>
#
</p>
</td>
</tr>
<tr>
<td>
<p>
ratio_add.fail
</p>
</td>
<td>
<p>
compile-fails
</p>
</td>
<td>
<p>
check ratio_add overflow metafunction class
</p>
</td>
<td>
<p>
Pass
</p>
</td>
<td>
<p>
#
</p>
</td>
</tr>
<tr>
<td>
<p>
ratio_subtract.fail
</p>
</td>
<td>
<p>
compile-fails
</p>
</td>
<td>
<p>
check ratio_subtract underflow metafunction class
</p>
</td>
<td>
<p>
Pass
</p>
</td>
<td>
<p>
#
</p>
</td>
</tr>
<tr>
<td>
<p>
ratio_multiply.fail
</p>
</td>
<td>
<p>
compile-fails
</p>
</td>
<td>
<p>
check ratio_multiply overflow metafunction class
</p>
</td>
<td>
<p>
Pass
</p>
</td>
<td>
<p>
#
</p>
</td>
</tr>
<tr>
<td>
<p>
ratio_divide.fail
</p>
</td>
<td>
<p>
compile-fails
</p>
</td>
<td>
<p>
check ratio_divide overflow metafunction class
</p>
</td>
<td>
<p>
Pass
</p>
</td>
<td>
<p>
#
</p>
</td>
</tr>
</tbody>
</table></div>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="ratio.appendices.tickets"></a><a class="link" href="appendices.html#ratio.appendices.tickets" title="Appendix G: Tickets">Appendix G: Tickets</a>
</h3></div></div></div>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
<col>
<col>
</colgroup>
<thead><tr>
<th>
<p>
Ticket
</p>
</th>
<th>
<p>
Description
</p>
</th>
<th>
<p>
Resolution
</p>
</th>
<th>
<p>
State
</p>
</th>
</tr></thead>
<tbody>
<tr>
<td>
<p>
1
</p>
</td>
<td>
<p>
result of metafunctions ratio_multiply and ratio_divide were not
normalized ratios.
</p>
</td>
<td>
<p>
Use of the nested ratio typedef type on ratio arithmetic operations.
</p>
</td>
<td>
<p>
Closed
</p>
</td>
</tr>
<tr>
<td>
<p>
2
</p>
</td>
<td>
<p>
INTMAX_C is not always defined.
</p>
</td>
<td>
<p>
Replace INTMAX_C by BOOST_INTMAX_C until boost/cstdint.hpp ensures
INTMAX_C is always defined.
</p>
</td>
<td>
<p>
Closed
</p>
</td>
</tr>
<tr>
<td>
<p>
3
</p>
</td>
<td>
<p>
MSVC reports a warning instead of an error when there is an integral
constant overflow.
</p>
</td>
<td>
<p>
manage with MSVC reporting a warning instead of an error when there
is an integral constant overflow.
</p>
</td>
<td>
<p>
Closed
</p>
</td>
</tr>
<tr>
<td>
<p>
4
</p>
</td>
<td>
<p>
ration_less overflow on cases where it can be avoided.
</p>
</td>
<td>
<p>
Change the algorithm as implemented in libc++.
</p>
</td>
<td>
<p>
Closed
</p>
</td>
</tr>
</tbody>
</table></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="ratio.appendices.todo"></a><a class="link" href="appendices.html#ratio.appendices.todo" title="Appendix H: Future Plans">Appendix H: Future Plans</a>
</h3></div></div></div>
<h5>
<a name="ratio.appendices.todo.h0"></a>
<span class="phrase"><a name="ratio.appendices.todo.for_later_releases"></a></span><a class="link" href="appendices.html#ratio.appendices.todo.for_later_releases">For
later releases</a>
</h5>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
Use template aliases on compiler providing it.
</li>
<li class="listitem">
Implement <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3135.html#3135" target="_top">multiple
arguments</a> ratio arithmetic.
</li>
</ul></div>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2008 Howard Hinnant<br>Copyright © 2006, 2008 Beman Dawes<br>Copyright © 2009-2012 Vicente
J. Botet Escriba<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="reference.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../ratio.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../signals2.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>