

modf()                   General Function                  modf()




Separate integral part and fraction

ddoouubbllee mmooddff(_r_e_a_l, _i_p) ddoouubbllee _r_e_a_l, *_i_p;

modf  is the  floating-point  modulus function.   It returns  the
fractional part of  its argument real, which is a  value f in the
range 0 <= _f < 1.  It also stores the integral part in the double
location referenced  by ip.   These numbers satisfy  the equation
_r_e_a_l = _f + *_i_p.

***** Example *****

This example  prompts for a  number from the  keyboard, then uses
mmooddff to calculate the number's fractional portion.


#include <stdio.h>

main()
{
        extern char *gets();
        extern double modf(), atof();
        double real, fp, ip;
        char string[64];



        for (;;) {
                printf("Enter number: ");
                if (gets(string) == 0)
                        break;



                real = atof(string);
                fp = modf(real, &ip);
                printf("%lf is the integral part of %lf\n",
                        ip, real);
                printf("%lf is the fractional part of %lf\n",
                        fp, real);
        }
}


***** See Also *****

atof(),  ceil(),  fabs(),  floor(),  frexp(),  general  function,
ldexp()








COHERENT Lexicon                                           Page 1


