mmooddff() -- General Function (libc)

Separate integral part and fraction
#iinncclluuddee <mmaatthh.hh>
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;

mmooddff() is  the floating-point modulus function.   It returns the fractional
part of its argument _r_e_a_l, and  stores the integral part in the location to
which _i_p points.  These numbers satisfy the equation _r_e_a_l = _f + *_i_p.

_E_x_a_m_p_l_e
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>
#include <stdlib.h>
#include <math.h>

main()
{
    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);
    }
}

_S_e_e _A_l_s_o
aattooff(), cceeiill(), ffaabbss(), fflloooorr(), ffrreexxpp(), llddeexxpp(), lliibbcc
ANSI Standard, section 7.5.4.6
POSIX Standard, section 8.1

_N_o_t_e_s
In releases  prior to  version 4.0,  the COHERENT implementation  of mmooddff()
handled negative numbers by returning a integral part less than _r_e_a_l, and a
positive fraction.  Now, it returns an integral part greater than _r_e_a_l, and
a  negative  fraction.   For  example,  the  old version  of  mmooddff()  would
transform -1.9 into  an integer of -2.0 and a  fraction of 0.1; whereas the
current version transforms  -1.9 into an integer of -1.0  and a fraction of
-0.9.

The behavior of mmooddff() was changed to conform to the ANSI Standard.
