modff Function

Splits a single precision floating-point value into fractional and integer parts.

Include

<math.h>

Prototype

float modff(float x, float *pint);

Arguments

x
single precision floating-point value
pint
pointer to a stored the integer part

Return Value

Returns the signed fractional part and pint points to the integer part.

Remarks

The absolute value of the fractional part is in the range of 0 (inclusive) to 1 (exclusive). No domain or range error will occur.

Example

#include <math.h>
#include <stdio.h>

int main(void)
{
  float x, y, n;

  x = 0.707F;
  y = modff(x, &n);
  printf("For %f the fraction is %f\n ", x, y);
  printf("  and the integer is %0.f\n\n", n);

  x = -15.2121F;
  y = modff(x, &n);
  printf("For %f the fraction is %f\n ", x, y);
  printf("  and the integer is %0.f\n\n", n);
}

Example Output

For 0.707000 the fraction is 0.707000
   and the integer is 0

For -15.212100 the fraction is -0.212100
   and the integer is -15