Annotation of cci/usr/src/lib/libc/tahoe/gen/atof.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

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