Namespaces
Variants
Views
Actions

std::modf

From cppreference.com
< cpp‎ | numeric‎ | math
Revision as of 22:35, 2 November 2012 by P12bot (Talk | contribs)

 
 
 
Common mathematical functions
Functions
Basic operations
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)(C++11)(C++11)
Exponential functions
(C++11)
(C++11)
(C++11)
(C++11)
Power functions
(C++11)
(C++11)
Trigonometric and hyperbolic functions
(C++11)
(C++11)
(C++11)
Error and gamma functions
(C++11)
(C++11)
(C++11)
(C++11)
Nearest integer floating point operations
(C++11)(C++11)(C++11)
(C++11)
(C++11)
(C++11)(C++11)(C++11)
Floating point manipulation functions
(C++11)(C++11)
(C++11)
(C++11)
modf
(C++11)(C++11)
(C++11)
Classification/Comparison
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
Macro constants
(C++11)(C++11)(C++11)(C++11)(C++11)
 

Template:ddcl list begin <tr class="t-dsc-header">

<td>
Defined in header <cmath>
</td>

<td></td> <td></td> <tr class="t-dcl-sep"><td></td><td></td><td></td></tr>

<tr class="t-dcl ">

<td class="t-dcl-nopad">
float       modf( float x, float* iptr );
</td>

<td class="t-dcl-nopad"> </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl-sep"><td></td><td></td><td></td></tr>

<tr class="t-dcl ">

<td class="t-dcl-nopad">
double      modf( double x, double* iptr );
</td>

<td class="t-dcl-nopad"> </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl-sep"><td></td><td></td><td></td></tr>

<tr class="t-dcl ">

<td class="t-dcl-nopad">
long double modf( long double x, long double* iptr );
</td>

<td class="t-dcl-nopad"> </td> <td class="t-dcl-nopad"> </td> </tr> Template:ddcl list end

Decomposes given floating point value x into integral and fractional parts, each having the same type and sign as x. The integral part (in floating-point format) is stored in the object pointed to by iptr.

Contents

Parameters

arg - floating point value
iptr - pointer to floating point value to store the integral part to

Return value

The fractional part of x with the same sign as x. The integral part is put into the value pointed to by iptr.

Example

#include <iostream>
#include <cmath>
int main()
{
    double f = 123.45;
    double f3;
    double f2 = std::modf(f, &f3);
    std::cout << "Given the number " << f  << ", "
              << "modf() makes " << f3 << " and " << f2 << '\n';
 
    f = -3.21;
    f2 = std::modf(f, &f3);
    std::cout << "Given the number " << f  << ", "
              << "modf() makes " << f3 << " and " << f2 << '\n';
}

Output:

Given the number 123.45, modf() makes 123 and 0.45
Given the number -3.21, modf() makes -3 and -0.21

See also

Template:cpp/numeric/math/dcl list trunc