|
|
1.1 root 1: /*
2: * libc/crt/modf.c
3: */
4:
5: /*
6: * double
7: * modf(real, dp)
8: * double real, *dp;
9: *
10: * modf() finds g = greatest integer <= real,
11: * then stores g through dp and returns real - g.
12: * This version uses a machine dependent subroutine
13: * double _modf(real, dp, e)
14: * which assumes real >= 0, 1 <= e = exponent(real) <= DMBITS+1,
15: * where DMBITS is the number of mantissa bits in a double.
16: */
17:
18: #if _IEEE
19: #define DEBITS 11
20: #define DMBITS 52
21: #define FEBITS 8
22: #define FMBITS 23
23: #endif
24:
25: #if _DECVAX
26: #define DEBITS 8
27: #define DMBITS 55
28: #define FEBITS 8
29: #define FMBITS 23
30: #endif
31:
32: extern double _modf();
33: extern double frexp();
34:
35: double
36: modf(d, dp) double d; register double *dp;
37: {
38: int e;
39:
40: frexp(d, &e);
41: if (e >= DMBITS+1) { /* very large d */
42: *dp = d;
43: return 0.0;
44: } else if (e <= 0) { /* -1. < d < 1. */
45: *dp = 0.0;
46: return d;
47: } else if (d >= 0.0)
48: return _modf(d, dp, e); /* d >= 0., 1 <= e < DMBITS+1 */
49:
50: /* d is negative. */
51: d = _modf(-d, dp, e);
52: *dp = -*dp;
53: return -d;
54: }
55:
56: /* end of modf.c */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.