| 236 | } |
| 237 | |
| 238 | double strtod(const char* str, char** endptr) { |
| 239 | if (!str) { |
| 240 | if (endptr) { |
| 241 | *endptr = const_cast<char*>(str); |
| 242 | } |
| 243 | return 0.0; |
| 244 | } |
| 245 | |
| 246 | const char* p = str; |
| 247 | double result = 0.0; |
| 248 | bool negative = false; |
| 249 | |
| 250 | // Skip leading whitespace |
| 251 | while (*p == ' ' || *p == '\t' || *p == '\n' || *p == '\r' || *p == '\f' || *p == '\v') { |
| 252 | p++; |
| 253 | } |
| 254 | |
| 255 | // Handle sign |
| 256 | if (*p == '-') { |
| 257 | negative = true; |
| 258 | p++; |
| 259 | } else if (*p == '+') { |
| 260 | p++; |
| 261 | } |
| 262 | |
| 263 | const char* start = p; |
| 264 | |
| 265 | // Parse integer part |
| 266 | while (*p >= '0' && *p <= '9') { |
| 267 | result = result * 10.0 + (*p - '0'); |
| 268 | p++; |
| 269 | } |
| 270 | |
| 271 | // Parse fractional part |
| 272 | if (*p == '.') { |
| 273 | p++; |
| 274 | double fraction = 0.1; |
| 275 | while (*p >= '0' && *p <= '9') { |
| 276 | result += (*p - '0') * fraction; |
| 277 | fraction *= 0.1; |
| 278 | p++; |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | // Parse exponent |
| 283 | if (*p == 'e' || *p == 'E') { |
| 284 | p++; |
| 285 | bool expNegative = false; |
| 286 | if (*p == '-') { |
| 287 | expNegative = true; |
| 288 | p++; |
| 289 | } else if (*p == '+') { |
| 290 | p++; |
| 291 | } |
| 292 | |
| 293 | int exp = 0; |
| 294 | while (*p >= '0' && *p <= '9') { |
| 295 | exp = exp * 10 + (*p - '0'); |
no outgoing calls
no test coverage detected