COHERENT manpages

This page displays the COHERENT manpage for modf() [Separate integral part and fraction].

List of available manpages
Index


modf() -- General Function (libc)

Separate integral part and fraction
#include <math.h>
double modf(real, ip)
double real, *ip;

modf() is  the floating-point modulus function.   It returns the fractional
part of its argument real, and  stores the integral part in the location to
which ip points.  These numbers satisfy the equation real = f + *ip.

Example

This example  prompts for a number  from the keyboard, then  uses modf() 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);
    }
}

See Also

atof(),
ceil(),
fabs(),
floor(),
frexp(),
ldexp(),
libc
ANSI Standard, §7.5.4.6
POSIX Standard, §8.1

Notes

In releases  prior to  version 4.0,  the COHERENT implementation  of modf()
handled negative numbers by returning a integral part less than real, and a
positive fraction.  Now, it returns an integral part greater than real, and
a  negative  fraction.   For  example,  the  old version  of  modf()  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 modf() was changed to conform to the ANSI Standard.