Go back to Richel Bilderbeek's homepage.

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

 

 

 

 

 

(C++) Fmod

 

Fmod is a math function to perform a modulus operation on doubles.

 

std::modf has a different purpose as Fmod: std::modf splits a double into its integer and a fractional part, for example it splits 12.34 into 12 and 0.34

 

#include <cassert>

double Fmod(const double x, const double mod)
{
  assert(mod != 0.0); //Cannot divide by zero
  return x - (mod * static_cast<int>(x / mod));
}

 

 

 

 

 

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

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict