1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>Integer and Fractional Part Splitting (modf)</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="trunc.html" title="Truncation Functions"> 10<link rel="next" href="../fpclass.html" title="Floating-Point Classification: Infinities and NaNs"> 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="trunc.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="../fpclass.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.modf"></a><a class="link" href="modf.html" title="Integer and Fractional Part Splitting (modf)">Integer and Fractional Part 28 Splitting (modf)</a> 29</h3></div></div></div> 30<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">modf</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></pre> 31<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> 32<span class="identifier">T</span> <span class="identifier">modf</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="identifier">T</span><span class="special">*</span> <span class="identifier">ipart</span><span class="special">);</span> 33 34<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> 35<span class="identifier">T</span> <span class="identifier">modf</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="identifier">T</span><span class="special">*</span> <span class="identifier">ipart</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">Policy</span><span class="special">&);</span> 36 37<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span> 38<span class="identifier">T</span> <span class="identifier">modf</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">int</span><span class="special">*</span> <span class="identifier">ipart</span><span class="special">);</span> 39 40<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> 41<span class="identifier">T</span> <span class="identifier">modf</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">int</span><span class="special">*</span> <span class="identifier">ipart</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">Policy</span><span class="special">&);</span> 42 43<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span> 44<span class="identifier">T</span> <span class="identifier">modf</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">long</span><span class="special">*</span> <span class="identifier">ipart</span><span class="special">);</span> 45 46<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> 47<span class="identifier">T</span> <span class="identifier">modf</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">long</span><span class="special">*</span> <span class="identifier">ipart</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">Policy</span><span class="special">&);</span> 48 49<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span> 50<span class="identifier">T</span> <span class="identifier">modf</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">long</span> <span class="keyword">long</span><span class="special">*</span> <span class="identifier">ipart</span><span class="special">);</span> 51 52<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> 53<span class="identifier">T</span> <span class="identifier">modf</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">long</span> <span class="keyword">long</span><span class="special">*</span> <span class="identifier">ipart</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">Policy</span><span class="special">&);</span> 54</pre> 55<p> 56 The <code class="computeroutput"><span class="identifier">modf</span></code> functions store 57 the integer part of <span class="emphasis"><em>v</em></span> in <code class="computeroutput"><span class="special">*</span><span class="identifier">ipart</span></code> and return the fractional part of 58 <span class="emphasis"><em>v</em></span>. The sign of the integer and fractional parts are 59 the same as the sign of <span class="emphasis"><em>v</em></span>. 60 </p> 61<p> 62 If the argument <span class="emphasis"><em>v</em></span> is either non-finite or else outside 63 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>: 64 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>. 65 </p> 66</div> 67<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 68<td align="left"></td> 69<td align="right"><div class="copyright-footer">Copyright © 2006-2019 Nikhar 70 Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos, 71 Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Matthew Pulver, Johan 72 Råde, Gautam Sewani, Benjamin Sobotta, Nicholas Thompson, Thijs van den Berg, 73 Daryle Walker and Xiaogang Zhang<p> 74 Distributed under the Boost Software License, Version 1.0. (See accompanying 75 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>) 76 </p> 77</div></td> 78</tr></table> 79<hr> 80<div class="spirit-nav"> 81<a accesskey="p" href="trunc.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="../fpclass.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a> 82</div> 83</body> 84</html> 85