mirror of
https://github.com/boostorg/safe_numerics.git
synced 2026-02-23 16:02:13 +00:00
92 lines
5.1 KiB
HTML
92 lines
5.1 KiB
HTML
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
|
<title>Introduction</title>
|
|
<link rel="stylesheet" href="boostbook.css" type="text/css">
|
|
<meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
|
|
<link rel="home" href="index.html" title="Safe Numerics">
|
|
<link rel="up" href="index.html" title="Safe Numerics">
|
|
<link rel="prev" href="index.html" title="Safe Numerics">
|
|
<link rel="next" href="tutorial.html" title="Tutorial">
|
|
</head>
|
|
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
|
<table cellpadding="2" width="100%"><tr>
|
|
<td valign="top"><img alt="pre-boost" width="30%" height="30%" src="pre-boost.jpg"></td>
|
|
<td align="center"><a href="../../index.html">Home</a></td>
|
|
<td align="center"><a href="">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="index.html"><img src="images/prev.png" alt="Prev"></a><a accesskey="u" href="index.html"><img src="images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="images/home.png" alt="Home"></a><a accesskey="n" href="tutorial.html"><img src="images/next.png" alt="Next"></a>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
|
<a name="safe_numerics.introduction"></a>Introduction</h2></div></div></div>
|
|
<div class="toc"><dl>
|
|
<dt><span class="section"><a href="introduction.html#idm49717634736">Problem</a></span></dt>
|
|
<dt><span class="section"><a href="introduction.html#idm49717631696">Solution</a></span></dt>
|
|
<dt><span class="section"><a href="introduction.html#idm49717628576">Requirements</a></span></dt>
|
|
</dl></div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h3 class="title">
|
|
<a name="idm49717634736"></a>Problem</h3></div></div></div>
|
|
<p>Arithmetic operations in C++ are NOT guarenteed to yield a correct
|
|
mathematical result. This feature is inherited from the early days of C.
|
|
The behavior of <code class="computeroutput">int</code>, <code class="computeroutput">unsigned int</code> and others
|
|
were designed to map closely to the underlying hardware. Computer hardware
|
|
implements these types as a fixed number of bits. When the result of
|
|
arithmetic operations exceeds this number of bits, the result is undefined
|
|
and usually not what the programmer intended. It is incumbent up the C/C++
|
|
programmer to guarentee that this behavior does not result in incorrect
|
|
behavior of the program. There are no language facilities which do this.
|
|
They have to be explicitly addressed in the program code. This is
|
|
exceeding tedious and laborious for a programmer to do. Besides, adding
|
|
this code would introduce another source of errors.</p>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h3 class="title">
|
|
<a name="idm49717631696"></a>Solution</h3></div></div></div>
|
|
<p>This library implements special versions of int, unsigned, etc.
|
|
which behave exactly like the original ones EXCEPT that the results of
|
|
these operations are checked to be sure any possible errors resulting from
|
|
undefined arithmetic behavior are trapped at compile time (if possible) or
|
|
at runtime.</p>
|
|
<p>In addition to eliminating undefined behavior from primitive integer
|
|
types, we define new data types <code class="computeroutput">safe_signed_range<MIN,
|
|
MAX></code> and <code class="computeroutput">safe_unsigned_range<MIN, MAX></code> which
|
|
will throw an exception if an attempt is made to store a result which is
|
|
outside the closed range [MIN, MAX].</p>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h3 class="title">
|
|
<a name="idm49717628576"></a>Requirements</h3></div></div></div>
|
|
<p>This library is is composed entirely of C++ Headers. I requires a
|
|
compiler compatible with the C++11 standard.</p>
|
|
<p>The following Boost Libraries must be installed in order to use this
|
|
library</p>
|
|
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
|
|
<li class="listitem"><p>mpl</p></li>
|
|
<li class="listitem"><p>integer</p></li>
|
|
<li class="listitem"><p>limits</p></li>
|
|
<li class="listitem"><p>config</p></li>
|
|
<li class="listitem"><p>concept checking</p></li>
|
|
<li class="listitem"><p>type traits</p></li>
|
|
<li class="listitem"><p>integer traits</p></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 © 2012 Robert Ramey<p><a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt">Subject to Boost Software License</a></p>
|
|
</div></td>
|
|
</tr></table>
|
|
<hr>
|
|
<div class="spirit-nav">
|
|
<a accesskey="p" href="index.html"><img src="images/prev.png" alt="Prev"></a><a accesskey="u" href="index.html"><img src="images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="images/home.png" alt="Home"></a><a accesskey="n" href="tutorial.html"><img src="images/next.png" alt="Next"></a>
|
|
</div>
|
|
</body>
|
|
</html>
|