Annotation of coherent/d/lib/libc/crt/_pow10.c,v, revision 1.1

1.1     ! root        1: head     1.2;
        !             2: access   ;
        !             3: symbols  ;
        !             4: locks    bin:1.2;
        !             5: comment  @ * @;
        !             6: 
        !             7: 
        !             8: 1.2
        !             9: date     90.04.23.22.19.30;  author bin;  state Exp;
        !            10: branches ;
        !            11: next   1.1;
        !            12: 
        !            13: 1.1
        !            14: date     90.04.23.22.10.04;  author bin;  state Exp;
        !            15: branches ;
        !            16: next   ;
        !            17: 
        !            18: 
        !            19: desc
        !            20: @Initial MWC RCS revision.
        !            21: Renamed _pow10.c, used to be pow10.c.
        !            22: @
        !            23: 
        !            24: 
        !            25: 1.2
        !            26: log
        !            27: @steve 4/23/90
        !            28: Replaced old COHERENT libc _pow10.c with modified version of MSDOS source.
        !            29: The modifications are a conditionalization on IEEE; the range of DECVAX
        !            30: exponents is much smaller than IEEE, so much of the big exponent table
        !            31: is unnecessary for DECVAX.
        !            32: @
        !            33: text
        !            34: @/*
        !            35:  * C general utilities library internals.
        !            36:  * _pow10()
        !            37:  * Compute 10.0^n.
        !            38:  * Assumes -319 <= DBL_MIN_10_EXP and DBL_MAX_10_EXP <= 319,
        !            39:  * which is true for IEEE-format doubles.
        !            40:  * Modified for MS-DOS from the standard ANSI library source.
        !            41:  */
        !            42: 
        !            43: /*
        !            44:  * There are lots of ways to do this, with varying accuracy, size, and speed.
        !            45:  * This version is nonrecursive and fast but uses somewhat bulky tables.
        !            46:  * It does the common cases -16 < exp < 16 by table lookup with no fp arithmetic.
        !            47:  * It does 16 <= exp <= DBL_MAX_10_EXP with one fp multiply.
        !            48:  * It does DBL_MIN_10_EXP <= exp <= -16 with one fp divide.
        !            49:  */
        !            50: 
        !            51: #include <math.h>
        !            52: 
        !            53: #if    IEEE
        !            54: #define        DBL_MAX_10_EXP  308
        !            55: #define DBL_MIN_10_EXP -307
        !            56: #else
        !            57: #define        DBL_MAX_10_EXP  38
        !            58: #define DBL_MIN_10_EXP -38
        !            59: #endif
        !            60: 
        !            61: static const double powtab0[] = {
        !            62:        1e0,    1e-1,   1e-2,   1e-3,   1e-4,   1e-5,   1e-6,   1e-7,
        !            63:        1e-8,   1e-9,   1e-10,  1e-11,  1e-12,  1e-13,  1e-14,  1e-15
        !            64: };
        !            65: 
        !            66: static const double powtab1[] = {
        !            67:        1e0,    1e1,    1e2,    1e3,    1e4,    1e5,    1e6,    1e7,
        !            68:        1e8,    1e9,    1e10,   1e11,   1e12,   1e13,   1e14,   1e15
        !            69: };
        !            70: 
        !            71: static const double powtab2[] = {
        !            72: #ifdef IEEE
        !            73:        1e16,   1e32,   1e48,   1e64,   1e80,   1e96,   1e112,  1e128,
        !            74:        1e144,  1e160,  1e176,  1e192,  1e208,  1e224,  1e240,  1e256,
        !            75:        1e272,  1e288,  1e304
        !            76: #else
        !            77:        1e16,   1e32
        !            78: #endif
        !            79: };
        !            80: 
        !            81: double
        !            82: _pow10(exp) register int exp;
        !            83: {
        !            84:        if (exp < 0) {
        !            85:                if ((exp = -exp) < 16)
        !            86:                        return powtab0[exp];
        !            87:                else if (exp <= -DBL_MIN_10_EXP)
        !            88:                        return powtab0[exp & 15] / powtab2[(exp >> 4) - 1];
        !            89:                else
        !            90:                        return 0.0;             /* exponent underflow */
        !            91:        }
        !            92:        else if (exp < 16)
        !            93:                return powtab1[exp];
        !            94:        else if (exp <= DBL_MAX_10_EXP)
        !            95:                return powtab1[exp & 15] * powtab2[(exp >> 4) - 1];
        !            96:        else
        !            97:                return HUGE_VAL;                /* exponent overflow */
        !            98: }
        !            99: @
        !           100: 
        !           101: 
        !           102: 1.1
        !           103: log
        !           104: @Initial revision
        !           105: @
        !           106: text
        !           107: @d2 6
        !           108: a7 3
        !           109:  * Compute 10**exp, as a double.
        !           110:  * Called from dtefg.c.
        !           111:  * This assumes that the exponent is in the range [-511,511].
        !           112: d9 39
        !           113: d49 1
        !           114: a49 2
        !           115: _pow10(exp)
        !           116: register int   exp;
        !           117: a50 7
        !           118:        register double d;
        !           119: 
        !           120:        static readonly double _powtab[] = {
        !           121:                1e0,    1e1,    1e2,    1e3,    1e4,    1e5,
        !           122:                1e6,    1e7,    1e8,    1e9,    1e10,   1e11,
        !           123:                1e12,   1e13,   1e14,   1e15 };
        !           124: 
        !           125: d52 6
        !           126: a57 1
        !           127:                return (1.0 / _pow10(-exp));
        !           128: d59 6
        !           129: a64 26
        !           130:        d = 1.0;
        !           131:        if (exp >= 256) {
        !           132:                exp -= 256;
        !           133:                d *= 1e256;
        !           134:        }
        !           135:        if (exp >= 128) {
        !           136:                exp -= 128;
        !           137:                d *= 1e128;
        !           138:        }
        !           139:        if (exp >= 64) {
        !           140:                exp -= 64;
        !           141:                d *= 1e64;
        !           142:        }
        !           143:        if (exp >= 32) {
        !           144:                exp -= 32;
        !           145:                d *= 1e32;
        !           146:        }
        !           147:        if (exp >= 16) {
        !           148:                exp -= 16;
        !           149:                d *= 1e16;
        !           150:        }
        !           151:        d *= _powtab[exp];
        !           152:        return (d);
        !           153: /*
        !           154:        return (d * _powtab[ exp]);
        !           155: */
        !           156: @

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.