Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) std::modf

 

std::modf splits a double into its integer and a fractional part, for example it splits 12.34 into 12 and 0.34.

 

 

#include <cmath>
#include <iostream>

int main()
{
  double int_part = 0.0;
  const double fraction_part = std::modf(M_E,&int_part);
  std::cout << M_E << " = "
    << int_part << " + " << fraction_part << '\n';
}

 

Screen output:

 

2.71828 = 2 + 0.718282

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict