|
|
coherent
modf() General Function modf()
Separate integral part and fraction
ddoouubbllee mmooddff(_r_e_a_l, _i_p) ddoouubbllee _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
mmooddff 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
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.