| 178 | } |
| 179 | |
| 180 | inline static const char* Atof(const char* p, double* out) { |
| 181 | int frac; |
| 182 | double sign, value, scale; |
| 183 | *out = NAN; |
| 184 | // Skip leading white space, if any. |
| 185 | while (*p == ' ') { |
| 186 | ++p; |
| 187 | } |
| 188 | // Get sign, if any. |
| 189 | sign = 1.0; |
| 190 | if (*p == '-') { |
| 191 | sign = -1.0; |
| 192 | ++p; |
| 193 | } else if (*p == '+') { |
| 194 | ++p; |
| 195 | } |
| 196 | |
| 197 | // is a number |
| 198 | if ((*p >= '0' && *p <= '9') || *p == '.' || *p == 'e' || *p == 'E') { |
| 199 | // Get digits before decimal point or exponent, if any. |
| 200 | for (value = 0.0; *p >= '0' && *p <= '9'; ++p) { |
| 201 | value = value * 10.0 + (*p - '0'); |
| 202 | } |
| 203 | |
| 204 | // Get digits after decimal point, if any. |
| 205 | if (*p == '.') { |
| 206 | double right = 0.0; |
| 207 | int nn = 0; |
| 208 | ++p; |
| 209 | while (*p >= '0' && *p <= '9') { |
| 210 | right = (*p - '0') + right * 10.0; |
| 211 | ++nn; |
| 212 | ++p; |
| 213 | } |
| 214 | value += right / Pow(10.0, nn); |
| 215 | } |
| 216 | |
| 217 | // Handle exponent, if any. |
| 218 | frac = 0; |
| 219 | scale = 1.0; |
| 220 | if ((*p == 'e') || (*p == 'E')) { |
| 221 | uint32_t expon; |
| 222 | // Get sign of exponent, if any. |
| 223 | ++p; |
| 224 | if (*p == '-') { |
| 225 | frac = 1; |
| 226 | ++p; |
| 227 | } else if (*p == '+') { |
| 228 | ++p; |
| 229 | } |
| 230 | // Get digits of exponent, if any. |
| 231 | for (expon = 0; *p >= '0' && *p <= '9'; ++p) { |
| 232 | expon = expon * 10 + (*p - '0'); |
| 233 | } |
| 234 | if (expon > 308) expon = 308; |
| 235 | // Calculate scaling factor. |
| 236 | while (expon >= 50) { scale *= 1E50; expon -= 50; } |
| 237 | while (expon >= 8) { scale *= 1E8; expon -= 8; } |
no test coverage detected