diff options
| author | Sadeep Madurange <smadurange@users.noreply.github.com> | 2021-12-05 13:00:16 +0800 |
|---|---|---|
| committer | Sadeep Madurange <smadurange@users.noreply.github.com> | 2021-12-05 13:00:16 +0800 |
| commit | 51f836e4a41b05574e0da9a45612ee70bf9fcaba (patch) | |
| tree | af18d649fea1327391b40a87a251796a9f8d5146 /4 | |
| parent | 3573f9e8fc065808a48322a4d40387ab8db4a5c2 (diff) | |
| download | k&r-exercises-51f836e4a41b05574e0da9a45612ee70bf9fcaba.tar.gz | |
4.2
Diffstat (limited to '4')
| -rw-r--r-- | 4/2.c | 8 |
1 files changed, 0 insertions, 8 deletions
@@ -29,16 +29,13 @@ double atof(char s[]) { ; sign = (s[i] == '-') ? -1 : 1; - if (s[i] == '+' || s[i] == '-') i++; for (val = 0.0; isdigit(s[i]); i++) val = 10.0 * val + (s[i] - '0'); - if (s[i] == '.') i++; - for (power = 1.0; isdigit(s[i]); i++) { val = 10.0 * val + (s[i] - '0'); power *= 10.0; @@ -46,18 +43,13 @@ double atof(char s[]) { if (s[i] == 'e' || s[i] == 'E') i++; - exp_sign = s[i] == '-' ? -1 : 1; - if (s[i] == '-' || s[i] == '+') i++; - for (exp = 0; isdigit(s[i]); i++) exp = 10 * exp + (s[i] - '0'); - if (exp_sign < 0) exp = exp_sign * exp; - if (exp < 0) { for (j = exp; j < 0; j++) power *= 10.0; |
