HP 3000 Manuals

modf [ HP C/iX Library Reference Manual ] MPE/iX 5.0 Documentation


HP C/iX Library Reference Manual

modf 

Accepts a double value and splits the value into its integer and
fractional parts.

Syntax 

     #include <math.h>
     double modf (double value, double *iptr);

Parameters 

value         A real number input to the function.

iptr          A pointer to a real number output from the function
              containing the integer part of value.

Return Values 

n             The signed fractional part of value.

Description 

The modf function splits value into two parts, a fraction and an integer,
such that fraction + integer = value.

iptr points to a double variable where the integer part of value is to be
stored.  The fractional part of value is the return value of the
function.

Example 

The following program shows how to use the modf function:

        main(argc, argv)
        int argc;
        char *argv[ ];
        {
           double value, iptr, frac, modf();
           sscanf(argv[1], "%lf", &value);
           frac = modf(value, &iptr);
           printf("Integer part: %g; Fractional part: %g\n", iptr, frac);
        }

The program accepts one argument and prints the integer and fractional
parts of that value.  Note that the address of iptr is passed to modf(),
because modf() expects the address of a double variable where the integer
part can be stored.

See Also 

ANSI C 4.5.4.6, POSIX.1 8.1



MPE/iX 5.0 Documentation