Annotation of researchv9/libc/gen/atof.c, revision 1.1

1.1     ! root        1: /*LINTLIBRARY*/
        !             2: /*
        !             3:  *     C library - ascii to floating
        !             4:  */
        !             5: 
        !             6: #include <ctype.h>
        !             7: 
        !             8: double
        !             9: atof(p)
        !            10: register char *p;
        !            11: {
        !            12:        register c;
        !            13:        double fl, flexp, exp5;
        !            14:        double big = 72057594037927936.;  /*2^56*/
        !            15:        double ldexp();
        !            16:        register eexp, exp, neg, negexp, bexp;
        !            17: 
        !            18:        neg = 1;
        !            19:        while(isspace(*p))
        !            20:                ++p;
        !            21:        if(*p == '-') {
        !            22:                ++p;
        !            23:                neg = -1;
        !            24:        }
        !            25:        else if(*p == '+')
        !            26:                ++p;
        !            27: 
        !            28:        exp = 0;
        !            29:        fl = 0;
        !            30:        while((c = *p++), isdigit(c))
        !            31:                if(fl < big)
        !            32:                        fl = 10*fl + (c-'0');
        !            33:                else
        !            34:                        exp++;
        !            35: 
        !            36:        if(c == '.')
        !            37:                while((c = *p++), isdigit(c))
        !            38:                        if(fl < big) {
        !            39:                                fl = 10*fl + (c-'0');
        !            40:                                exp--;
        !            41:                        }
        !            42: 
        !            43:        negexp = 1;
        !            44:        eexp = 0;
        !            45:        if((c == 'E') || (c == 'e')) {
        !            46:                if((c = *p++) == '+')
        !            47:                        ;
        !            48:                else if(c == '-')
        !            49:                        negexp = -1;
        !            50:                     else
        !            51:                        --p;
        !            52: 
        !            53:                while((c = *p++), isdigit(c))
        !            54:                        eexp = 10*eexp + (c-'0');
        !            55: 
        !            56:                if(negexp < 0)
        !            57:                        eexp = -eexp;
        !            58:                exp = exp + eexp;
        !            59:        }
        !            60: 
        !            61:        negexp = 1;
        !            62:        if(exp < 0) {
        !            63:                negexp = -1;
        !            64:                exp = -exp;
        !            65:        }
        !            66: 
        !            67:        flexp = 1;
        !            68:        exp5 = 5;
        !            69:        bexp = exp;
        !            70:        while(1) {
        !            71:                if(exp&01)
        !            72:                        flexp *= exp5;
        !            73:                exp >>= 1;
        !            74:                if(exp == 0)
        !            75:                        break;
        !            76:                exp5 *= exp5;
        !            77:        }
        !            78:        if(negexp < 0)
        !            79:                fl /= flexp;
        !            80:        else
        !            81:                fl *= flexp;
        !            82:        fl = ldexp(fl, negexp*bexp);
        !            83:        if(neg < 0)
        !            84:                fl = -fl;
        !            85:        return(fl);
        !            86: }

unix.superglobalmegacorp.com

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