|
|
1.1 root 1: /*
2: * C general utilities library internals.
3: * _pow10()
4: * Compute 10.0^n.
5: * Assumes -319 <= DBL_MIN_10_EXP and DBL_MAX_10_EXP <= 319,
6: * which is true for IEEE-format doubles.
7: * Modified for MS-DOS from the standard ANSI library source.
8: */
9:
10: /*
11: * There are lots of ways to do this, with varying accuracy, size, and speed.
12: * This version is nonrecursive and fast but uses somewhat bulky tables.
13: * It does the common cases -16 < exp < 16 by table lookup with no fp arithmetic.
14: * It does 16 <= exp <= DBL_MAX_10_EXP with one fp multiply.
15: * It does DBL_MIN_10_EXP <= exp <= -16 with one fp divide.
16: */
17:
18: #include <math.h>
19: #include <float.h>
20:
21: static const double powtab0[] = {
22: 1e0, 1e-1, 1e-2, 1e-3, 1e-4, 1e-5, 1e-6, 1e-7,
23: 1e-8, 1e-9, 1e-10, 1e-11, 1e-12, 1e-13, 1e-14, 1e-15
24: };
25:
26: static const double powtab1[] = {
27: 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7,
28: 1e8, 1e9, 1e10, 1e11, 1e12, 1e13, 1e14, 1e15
29: };
30:
31: static const double powtab2[] = {
32: #if _IEEE
33: 1e16, 1e32, 1e48, 1e64, 1e80, 1e96, 1e112, 1e128,
34: 1e144, 1e160, 1e176, 1e192, 1e208, 1e224, 1e240, 1e256,
35: 1e272, 1e288, 1e304
36: #endif
37: #if _DECVAX
38: 1e16, 1e32
39: #endif
40: };
41:
42: double
43: _pow10(exp) register int exp;
44: {
45: if (exp < 0) {
46: if ((exp = -exp) < 16)
47: return powtab0[exp];
48: else if (exp <= -DBL_MIN_10_EXP)
49: return powtab0[exp & 15] / powtab2[(exp >> 4) - 1];
50: else
51: return 0.0; /* exponent underflow */
52: }
53: else if (exp < 16)
54: return powtab1[exp];
55: else if (exp <= DBL_MAX_10_EXP)
56: return powtab1[exp & 15] * powtab2[(exp >> 4) - 1];
57: else
58: return HUGE_VAL; /* exponent overflow */
59: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.