modfl Function

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

Include

<math.h>

Prototype

long double modfl(long double x, long double *pint);

Arguments

x
double 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)
{
  long double x, y, n;

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

  x = -15.2121;
  y = modfl(x, &n);
  printf("For %Lf the fraction is %Lf\n ", x, y);
  printf("  and the integer is %0.Lf\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