modf - C math.h

C examples for math.h:modf

Type

function

From

<cmath>
<ctgmath>
<math.h>

Description

Breaks x into an integral and a fractional part.

The integer part is stored in the object pointed by intpart, and the fractional part is returned by the function.

Both parts have the same sign as x.

Prototype

long double modfl (long double x, long double* intpart);
long double modf (long double x, long double* intpart);
     double modf (double x, double* intpart);
      float modff (float x      , float* intpart);
     double modf (T x          , double* intpart);       

Parameters

Parameter Description
x Floating point value to break into parts.
intpart Pointer to an object where the integral part is stored with the same sign as x.

Return Value

The fractional part of x, with the same sign.

Example

Demo Code


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

int main ()/*from  w ww . j  a  va  2 s .c o  m*/
{
  double param = 3.14, fractpart, intpart;

  fractpart = modf (param , &intpart);
  printf ("%f = %f + %f \n", param, intpart, fractpart);
  return 0;
}

Related Tutorials