|
|
1.1 root 1:
2:
3: modf() General Function modf()
4:
5:
6:
7:
8: Separate integral part and fraction
9:
10: ddoouubbllee mmooddff(_r_e_a_l, _i_p) ddoouubbllee _r_e_a_l, *_i_p;
11:
12: modf is the floating-point modulus function. It returns the
13: fractional part of its argument real, which is a value f in the
14: range 0 <= _f < 1. It also stores the integral part in the double
15: location referenced by ip. These numbers satisfy the equation
16: _r_e_a_l = _f + *_i_p.
17:
18: ***** Example *****
19:
20: This example prompts for a number from the keyboard, then uses
21: mmooddff to calculate the number's fractional portion.
22:
23:
24: #include <stdio.h>
25:
26: main()
27: {
28: extern char *gets();
29: extern double modf(), atof();
30: double real, fp, ip;
31: char string[64];
32:
33:
34:
35: for (;;) {
36: printf("Enter number: ");
37: if (gets(string) == 0)
38: break;
39:
40:
41:
42: real = atof(string);
43: fp = modf(real, &ip);
44: printf("%lf is the integral part of %lf\n",
45: ip, real);
46: printf("%lf is the fractional part of %lf\n",
47: fp, real);
48: }
49: }
50:
51:
52: ***** See Also *****
53:
54: atof(), ceil(), fabs(), floor(), frexp(), general function,
55: ldexp()
56:
57:
58:
59:
60:
61:
62:
63:
64: COHERENT Lexicon Page 1
65:
66:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.