1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>Truncation Functions</title> 5<link rel="stylesheet" href="../../math.css" type="text/css"> 6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1"> 7<link rel="home" href="../../index.html" title="Math Toolkit 2.12.0"> 8<link rel="up" href="../rounding.html" title="Rounding Truncation and Integer Conversion"> 9<link rel="prev" href="round.html" title="Rounding Functions"> 10<link rel="next" href="modf.html" title="Integer and Fractional Part Splitting (modf)"> 11</head> 12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> 13<table cellpadding="2" width="100%"><tr> 14<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td> 15<td align="center"><a href="../../../../../../index.html">Home</a></td> 16<td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td> 17<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> 18<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> 19<td align="center"><a href="../../../../../../more/index.htm">More</a></td> 20</tr></table> 21<hr> 22<div class="spirit-nav"> 23<a accesskey="p" href="round.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../rounding.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="modf.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a> 24</div> 25<div class="section"> 26<div class="titlepage"><div><div><h3 class="title"> 27<a name="math_toolkit.rounding.trunc"></a><a class="link" href="trunc.html" title="Truncation Functions">Truncation Functions</a> 28</h3></div></div></div> 29<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">math</span><span class="special">/</span><span class="identifier">special_functions</span><span class="special">/</span><span class="identifier">trunc</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></pre> 30<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span> 31<span class="identifier">T</span> <span class="identifier">trunc</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">T</span><span class="special">&</span> <span class="identifier">v</span><span class="special">);</span> 32 33<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Policy</span><span class="special">></span> 34<span class="identifier">T</span> <span class="identifier">trunc</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">T</span><span class="special">&</span> <span class="identifier">v</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">Policy</span><span class="special">&);</span> 35 36<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span> 37<span class="keyword">int</span> <span class="identifier">itrunc</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">T</span><span class="special">&</span> <span class="identifier">v</span><span class="special">);</span> 38 39<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Policy</span><span class="special">></span> 40<span class="keyword">int</span> <span class="identifier">itrunc</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">T</span><span class="special">&</span> <span class="identifier">v</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">Policy</span><span class="special">&);</span> 41 42<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span> 43<span class="keyword">long</span> <span class="identifier">ltrunc</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">T</span><span class="special">&</span> <span class="identifier">v</span><span class="special">);</span> 44 45<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Policy</span><span class="special">></span> 46<span class="keyword">long</span> <span class="identifier">ltrunc</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">T</span><span class="special">&</span> <span class="identifier">v</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">Policy</span><span class="special">&);</span> 47 48<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span> 49<span class="keyword">long</span> <span class="keyword">long</span> <span class="identifier">lltrunc</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">T</span><span class="special">&</span> <span class="identifier">v</span><span class="special">);</span> 50 51<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Policy</span><span class="special">></span> 52<span class="keyword">long</span> <span class="keyword">long</span> <span class="identifier">lltrunc</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">T</span><span class="special">&</span> <span class="identifier">v</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">Policy</span><span class="special">&);</span> 53</pre> 54<p> 55 The trunc functions round their argument to the integer value, nearest to 56 but no larger in magnitude than the argument. 57 </p> 58<p> 59 For example <code class="computeroutput"><span class="identifier">itrunc</span><span class="special">(</span><span class="number">3.7</span><span class="special">)</span></code> would 60 return <code class="computeroutput"><span class="number">3</span></code> and <code class="computeroutput"><span class="identifier">ltrunc</span><span class="special">(-</span><span class="number">4.6</span><span class="special">)</span></code> 61 would return <code class="computeroutput"><span class="special">-</span><span class="number">4</span></code>. 62 </p> 63<p> 64 If the argument <span class="emphasis"><em>v</em></span> is either non-finite or else outside 65 the range of the result type, then returns the result of <a class="link" href="../error_handling.html#math_toolkit.error_handling.rounding_error">rounding_error</a>: 66 by default this throws an instance of <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">rounding_error</span></code>. 67 </p> 68</div> 69<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 70<td align="left"></td> 71<td align="right"><div class="copyright-footer">Copyright © 2006-2019 Nikhar 72 Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos, 73 Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Matthew Pulver, Johan 74 Råde, Gautam Sewani, Benjamin Sobotta, Nicholas Thompson, Thijs van den Berg, 75 Daryle Walker and Xiaogang Zhang<p> 76 Distributed under the Boost Software License, Version 1.0. (See accompanying 77 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>) 78 </p> 79</div></td> 80</tr></table> 81<hr> 82<div class="spirit-nav"> 83<a accesskey="p" href="round.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../rounding.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="modf.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a> 84</div> 85</body> 86</html> 87