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