LEFT | RIGHT |
1 /* -*- Mode: C; c-file-style: "python" -*- */ | 1 /* -*- Mode: C; c-file-style: "python" -*- */ |
2 | 2 |
3 #include <Python.h> | 3 #include <Python.h> |
4 #include <locale.h> | 4 #include <locale.h> |
5 | 5 |
6 /* ascii character tests (as opposed to locale tests) */ | 6 /* ascii character tests (as opposed to locale tests) */ |
7 #define ISSPACE(c) ((c) == ' ' || (c) == '\f' || (c) == '\n' || \ | 7 #define ISSPACE(c) ((c) == ' ' || (c) == '\f' || (c) == '\n' || \ |
8 (c) == '\r' || (c) == '\t' || (c) == '\v') | 8 (c) == '\r' || (c) == '\t' || (c) == '\v') |
9 #define ISDIGIT(c) ((c) >= '0' && (c) <= '9') | 9 #define ISDIGIT(c) ((c) >= '0' && (c) <= '9') |
10 | 10 |
(...skipping 19 matching lines...) Expand all Loading... |
30 * is returned (according to the sign of the value), and %ERANGE is | 30 * is returned (according to the sign of the value), and %ERANGE is |
31 * stored in %errno. If the correct value would cause underflow, | 31 * stored in %errno. If the correct value would cause underflow, |
32 * zero is returned and %ERANGE is stored in %errno. | 32 * zero is returned and %ERANGE is stored in %errno. |
33 * If memory allocation fails, %ENOMEM is stored in %errno. | 33 * If memory allocation fails, %ENOMEM is stored in %errno. |
34 *· | 34 *· |
35 * This function resets %errno before calling strtod() so that | 35 * This function resets %errno before calling strtod() so that |
36 * you can reliably detect overflow and underflow. | 36 * you can reliably detect overflow and underflow. |
37 * | 37 * |
38 * Return value: the #gdouble value. | 38 * Return value: the #gdouble value. |
39 **/ | 39 **/ |
| 40 |
| 41 #ifndef PY_NO_SHORT_FLOAT_REPR |
| 42 |
40 double | 43 double |
41 PyOS_ascii_strtod(const char *nptr, char **endptr) | 44 PyOS_ascii_strtod(const char *nptr, char **endptr) |
42 { | 45 { |
43 double result; | 46 double result; |
44 _Py_SET_53BIT_PRECISION_HEADER; | 47 _Py_SET_53BIT_PRECISION_HEADER; |
45 | 48 |
46 assert(nptr != NULL); | 49 assert(nptr != NULL); |
47 /* Set errno to zero, so that we can distinguish zero results | 50 /* Set errno to zero, so that we can distinguish zero results |
48 and underflows */ | 51 and underflows */ |
49 errno = 0; | 52 errno = 0; |
50 | 53 |
51 _Py_SET_53BIT_PRECISION_START; | 54 _Py_SET_53BIT_PRECISION_START; |
52 result = _Py_dg_strtod(nptr, endptr); | 55 result = _Py_dg_strtod(nptr, endptr); |
53 _Py_SET_53BIT_PRECISION_END; | 56 _Py_SET_53BIT_PRECISION_END; |
54 | 57 |
55 return result; | 58 return result; |
56 | 59 |
57 } | 60 } |
58 | 61 |
| 62 #else |
| 63 |
| 64 /* |
| 65 Use system strtod; since strtod is locale aware, we may |
| 66 have to first fix the decimal separator. |
| 67 |
| 68 Note that unlike _Py_dg_strtod, the system strtod may not always give |
| 69 correctly rounded results. |
| 70 */ |
| 71 |
59 double | 72 double |
60 PyOS_ascii_strtod_fallback(const char *nptr, char **endptr) | 73 PyOS_ascii_strtod(const char *nptr, char **endptr) |
61 { | 74 { |
62 char *fail_pos; | 75 char *fail_pos; |
63 double val = -1.0; | 76 double val = -1.0; |
64 struct lconv *locale_data; | 77 struct lconv *locale_data; |
65 const char *decimal_point; | 78 const char *decimal_point; |
66 size_t decimal_point_len; | 79 size_t decimal_point_len; |
67 const char *p, *decimal_point_pos; | 80 const char *p, *decimal_point_pos; |
68 const char *end = NULL; /* Silence gcc */ | 81 const char *end = NULL; /* Silence gcc */ |
69 const char *digits_pos = NULL; | 82 const char *digits_pos = NULL; |
70 int negate = 0; | 83 int negate = 0; |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 fail_pos = (char *)nptr; | 211 fail_pos = (char *)nptr; |
199 | 212 |
200 if (negate && fail_pos != nptr) | 213 if (negate && fail_pos != nptr) |
201 val = -val; | 214 val = -val; |
202 | 215 |
203 if (endptr) | 216 if (endptr) |
204 *endptr = fail_pos; | 217 *endptr = fail_pos; |
205 | 218 |
206 return val; | 219 return val; |
207 } | 220 } |
| 221 |
| 222 #endif |
| 223 |
| 224 double |
| 225 PyOS_ascii_atof(const char *nptr) |
| 226 { |
| 227 return PyOS_ascii_strtod(nptr, NULL); |
| 228 } |
| 229 |
208 | 230 |
209 /* Given a string that may have a decimal point in the current | 231 /* Given a string that may have a decimal point in the current |
210 locale, change it back to a dot. Since the string cannot get | 232 locale, change it back to a dot. Since the string cannot get |
211 longer, no need for a maximum buffer size parameter. */ | 233 longer, no need for a maximum buffer size parameter. */ |
212 Py_LOCAL_INLINE(void) | 234 Py_LOCAL_INLINE(void) |
213 change_decimal_from_locale_to_dot(char* buffer) | 235 change_decimal_from_locale_to_dot(char* buffer) |
214 { | 236 { |
215 struct lconv *locale_data = localeconv(); | 237 struct lconv *locale_data = localeconv(); |
216 const char *decimal_point = locale_data->decimal_point; | 238 const char *decimal_point = locale_data->decimal_point; |
217 | 239 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 if (start + zeros + exponent_digit_cnt + 1 | 326 if (start + zeros + exponent_digit_cnt + 1 |
305 < buffer + buf_size) { | 327 < buffer + buf_size) { |
306 memmove(start + zeros, start, | 328 memmove(start + zeros, start, |
307 exponent_digit_cnt + 1); | 329 exponent_digit_cnt + 1); |
308 memset(start, '0', zeros); | 330 memset(start, '0', zeros); |
309 } | 331 } |
310 } | 332 } |
311 } | 333 } |
312 } | 334 } |
313 | 335 |
314 /* Ensure that buffer has a decimal point in it. The decimal point | 336 /* Ensure that buffer has a decimal point in it. The decimal point will not |
315 will not be in the current locale, it will always be '.' */ | 337 be in the current locale, it will always be '.'. Don't add a decimal if an |
| 338 exponent is present. */ |
316 Py_LOCAL_INLINE(void) | 339 Py_LOCAL_INLINE(void) |
317 ensure_decimal_point(char* buffer, size_t buf_size) | 340 ensure_decimal_point(char* buffer, size_t buf_size) |
318 { | 341 { |
319 int insert_count = 0; | 342 int insert_count = 0; |
320 char* chars_to_insert; | 343 char* chars_to_insert; |
321 | 344 |
322 /* search for the first non-digit character */ | 345 /* search for the first non-digit character */ |
323 char *p = buffer; | 346 char *p = buffer; |
324 if (*p == '-' || *p == '+') | 347 if (*p == '-' || *p == '+') |
325 /* Skip leading sign, if present. I think this could only | 348 /* Skip leading sign, if present. I think this could only |
326 ever be '-', but it can't hurt to check for both. */ | 349 ever be '-', but it can't hurt to check for both. */ |
327 ++p; | 350 ++p; |
328 while (*p && isdigit(Py_CHARMASK(*p))) | 351 while (*p && isdigit(Py_CHARMASK(*p))) |
329 ++p; | 352 ++p; |
330 | 353 |
331 if (*p == '.') { | 354 if (*p == '.') { |
332 if (isdigit(Py_CHARMASK(*(p+1)))) { | 355 if (isdigit(Py_CHARMASK(*(p+1)))) { |
333 /* Nothing to do, we already have a decimal | 356 /* Nothing to do, we already have a decimal |
334 point and a digit after it */ | 357 point and a digit after it */ |
335 } | 358 } |
336 else { | 359 else { |
337 /* We have a decimal point, but no following | 360 /* We have a decimal point, but no following |
338 digit. Insert a zero after the decimal. */ | 361 digit. Insert a zero after the decimal. */ |
339 ++p; | 362 ++p; |
340 chars_to_insert = "0"; | 363 chars_to_insert = "0"; |
341 insert_count = 1; | 364 insert_count = 1; |
342 } | 365 } |
343 } | 366 } |
344 » else { | 367 » else if (!(*p == 'e' || *p == 'E')) { |
| 368 » » /* Don't add ".0" if we have an exponent. */ |
345 chars_to_insert = ".0"; | 369 chars_to_insert = ".0"; |
346 insert_count = 2; | 370 insert_count = 2; |
347 } | 371 } |
348 if (insert_count) { | 372 if (insert_count) { |
349 size_t buf_len = strlen(buffer); | 373 size_t buf_len = strlen(buffer); |
350 if (buf_len + insert_count + 1 >= buf_size) { | 374 if (buf_len + insert_count + 1 >= buf_size) { |
351 /* If there is not enough room in the buffer | 375 /* If there is not enough room in the buffer |
352 for the additional text, just skip it. It's | 376 for the additional text, just skip it. It's |
353 not worth generating an error over. */ | 377 not worth generating an error over. */ |
354 } | 378 } |
355 else { | 379 else { |
356 memmove(p + insert_count, p, | 380 memmove(p + insert_count, p, |
357 buffer + strlen(buffer) - p + 1); | 381 buffer + strlen(buffer) - p + 1); |
358 memcpy(p, chars_to_insert, insert_count); | 382 memcpy(p, chars_to_insert, insert_count); |
359 } | 383 } |
360 } | 384 } |
361 } | |
362 | |
363 /* Add the locale specific grouping characters to buffer. Note | |
364 that any decimal point (if it's present) in buffer is already | |
365 locale-specific. Return 0 on error, else 1. */ | |
366 Py_LOCAL_INLINE(int) | |
367 add_thousands_grouping(char* buffer, size_t buf_size) | |
368 { | |
369 #if 0 | |
370 Py_ssize_t len = strlen(buffer); | |
371 struct lconv *locale_data = localeconv(); | |
372 const char *decimal_point = locale_data->decimal_point; | |
373 | |
374 /* Find the decimal point, if any. We're only concerned | |
375 about the characters to the left of the decimal when | |
376 adding grouping. */ | |
377 char *p = strstr(buffer, decimal_point); | |
378 if (!p) { | |
379 /* No decimal, use the entire string. */ | |
380 | |
381 /* If any exponent, adjust p. */ | |
382 p = strpbrk(buffer, "eE"); | |
383 if (!p) | |
384 /* No exponent and no decimal. Use the entire | |
385 string. */ | |
386 p = buffer + len; | |
387 } | |
388 /* At this point, p points just past the right-most character we | |
389 want to format. We need to add the grouping string for the | |
390 characters between buffer and p. */ | |
391 return _PyBytes_InsertThousandsGroupingLocale(buffer, len, p-buffer, | |
392 buf_size, NULL, 1, 1); | |
393 #endif | |
394 return 1; | |
395 } | 385 } |
396 | 386 |
397 /* see FORMATBUFLEN in unicodeobject.c */ | 387 /* see FORMATBUFLEN in unicodeobject.c */ |
398 #define FLOAT_FORMATBUFLEN 120 | 388 #define FLOAT_FORMATBUFLEN 120 |
399 | 389 |
400 /** | 390 /** |
401 * PyOS_ascii_formatd: | 391 * PyOS_ascii_formatd: |
402 * @buffer: A buffer to place the resulting string in | 392 * @buffer: A buffer to place the resulting string in |
403 * @buf_size: The length of the buffer. | 393 * @buf_size: The length of the buffer. |
404 * @format: The printf()-style format to use for the | 394 * @format: The printf()-style format to use for the |
405 * code to use for converting.· | 395 * code to use for converting.· |
406 * @d: The #gdouble to convert | 396 * @d: The #gdouble to convert |
407 * | 397 * |
408 * Converts a #gdouble to a string, using the '.' as | 398 * Converts a #gdouble to a string, using the '.' as |
409 * decimal point. To format the number you pass in | 399 * decimal point. To format the number you pass in |
410 * a printf()-style format string. Allowed conversion | 400 * a printf()-style format string. Allowed conversion |
411 * specifiers are 'e', 'E', 'f', 'F', 'g', 'G', and 'n'. | 401 * specifiers are 'e', 'E', 'f', 'F', 'g', 'G', and 'Z'. |
412 *· | 402 *· |
413 * 'n' is the same as 'g', except it uses the current locale. | |
414 * 'Z' is the same as 'g', except it always has a decimal and | 403 * 'Z' is the same as 'g', except it always has a decimal and |
415 * at least one digit after the decimal. | 404 * at least one digit after the decimal. |
416 * | 405 * |
417 * Return value: The pointer to the buffer with the converted string. | 406 * Return value: The pointer to the buffer with the converted string. |
418 **/ | 407 **/ |
419 char * | 408 char * |
420 PyOS_ascii_formatd(char *buffer,· | 409 PyOS_ascii_formatd(char *buffer,· |
421 size_t buf_size,· | 410 size_t buf_size,· |
422 const char *format,· | 411 const char *format,· |
423 double d) | 412 double d) |
424 { | 413 { |
425 char format_char; | 414 char format_char; |
426 size_t format_len = strlen(format); | 415 size_t format_len = strlen(format); |
427 | 416 |
428 /* For type 'n', we need to make a copy of the format string, because | |
429 we're going to modify 'n' -> 'g', and format is const char*, so we | |
430 can't modify it directly. FLOAT_FORMATBUFLEN should be longer than | |
431 we ever need this to be. There's an upcoming check to ensure it's | |
432 big enough. */ | |
433 /* Issue 2264: code 'Z' requires copying the format. 'Z' is 'g', but | 417 /* Issue 2264: code 'Z' requires copying the format. 'Z' is 'g', but |
434 also with at least one character past the decimal. */ | 418 also with at least one character past the decimal. */ |
435 char tmp_format[FLOAT_FORMATBUFLEN]; | 419 char tmp_format[FLOAT_FORMATBUFLEN]; |
436 | 420 |
437 /* The last character in the format string must be the format char */ | 421 /* The last character in the format string must be the format char */ |
438 format_char = format[format_len - 1]; | 422 format_char = format[format_len - 1]; |
439 | 423 |
440 if (format[0] != '%') | 424 if (format[0] != '%') |
441 return NULL; | 425 return NULL; |
442 | 426 |
443 /* I'm not sure why this test is here. It's ensuring that the format | 427 /* I'm not sure why this test is here. It's ensuring that the format |
444 string after the first character doesn't have a single quote, a | 428 string after the first character doesn't have a single quote, a |
445 lowercase l, or a percent. This is the reverse of the commented-out | 429 lowercase l, or a percent. This is the reverse of the commented-out |
446 test about 10 lines ago. */ | 430 test about 10 lines ago. */ |
447 if (strpbrk(format + 1, "'l%")) | 431 if (strpbrk(format + 1, "'l%")) |
448 return NULL; | 432 return NULL; |
449 | 433 |
450 /* Also curious about this function is that it accepts format strings | 434 /* Also curious about this function is that it accepts format strings |
451 like "%xg", which are invalid for floats. In general, the | 435 like "%xg", which are invalid for floats. In general, the |
452 interface to this function is not very good, but changing it is | 436 interface to this function is not very good, but changing it is |
453 difficult because it's a public API. */ | 437 difficult because it's a public API. */ |
454 | 438 |
455 if (!(format_char == 'e' || format_char == 'E' ||· | 439 if (!(format_char == 'e' || format_char == 'E' ||· |
456 format_char == 'f' || format_char == 'F' ||· | 440 format_char == 'f' || format_char == 'F' ||· |
457 format_char == 'g' || format_char == 'G' || | 441 format_char == 'g' || format_char == 'G' || |
458 » format_char == 'n' || format_char == 'Z')) | 442 » format_char == 'Z')) |
459 return NULL; | 443 return NULL; |
460 | 444 |
461 » /* Map 'n' or 'Z' format_char to 'g', by copying the format string and | 445 » /* Map 'Z' format_char to 'g', by copying the format string and |
462 replacing the final char with a 'g' */ | 446 replacing the final char with a 'g' */ |
463 » if (format_char == 'n' || format_char == 'Z') { | 447 » if (format_char == 'Z') { |
464 if (format_len + 1 >= sizeof(tmp_format)) { | 448 if (format_len + 1 >= sizeof(tmp_format)) { |
465 /* The format won't fit in our copy. Error out. In | 449 /* The format won't fit in our copy. Error out. In |
466 practice, this will never happen and will be | 450 practice, this will never happen and will be |
467 detected by returning NULL */ | 451 detected by returning NULL */ |
468 return NULL; | 452 return NULL; |
469 } | 453 } |
470 strcpy(tmp_format, format); | 454 strcpy(tmp_format, format); |
471 tmp_format[format_len - 1] = 'g'; | 455 tmp_format[format_len - 1] = 'g'; |
472 format = tmp_format; | 456 format = tmp_format; |
473 } | 457 } |
474 | 458 |
475 | 459 |
476 /* Have PyOS_snprintf do the hard work */ | 460 /* Have PyOS_snprintf do the hard work */ |
477 PyOS_snprintf(buffer, buf_size, format, d); | 461 PyOS_snprintf(buffer, buf_size, format, d); |
478 | 462 |
479 /* Do various fixups on the return string */ | 463 /* Do various fixups on the return string */ |
480 | 464 |
481 /* Get the current locale, and find the decimal point string. | 465 /* Get the current locale, and find the decimal point string. |
482 » Convert that string back to a dot. Do not do this if using the | 466 » Convert that string back to a dot. */ |
483 » 'n' (number) format code, since we want to keep the localized | 467 » change_decimal_from_locale_to_dot(buffer); |
484 » decimal point in that case. */ | |
485 » if (format_char != 'n') | |
486 » » change_decimal_from_locale_to_dot(buffer); | |
487 | 468 |
488 /* If an exponent exists, ensure that the exponent is at least | 469 /* If an exponent exists, ensure that the exponent is at least |
489 MIN_EXPONENT_DIGITS digits, providing the buffer is large enough | 470 MIN_EXPONENT_DIGITS digits, providing the buffer is large enough |
490 for the extra zeros. Also, if there are more than | 471 for the extra zeros. Also, if there are more than |
491 MIN_EXPONENT_DIGITS, remove as many zeros as possible until we get | 472 MIN_EXPONENT_DIGITS, remove as many zeros as possible until we get |
492 back to MIN_EXPONENT_DIGITS */ | 473 back to MIN_EXPONENT_DIGITS */ |
493 ensure_minumim_exponent_length(buffer, buf_size); | 474 ensure_minumim_exponent_length(buffer, buf_size); |
494 | 475 |
495 /* If format_char is 'Z', make sure we have at least one character | 476 /* If format_char is 'Z', make sure we have at least one character |
496 after the decimal point (and make sure we have a decimal point). */ | 477 after the decimal point (and make sure we have a decimal point). */ |
497 if (format_char == 'Z') | 478 if (format_char == 'Z') |
498 ensure_decimal_point(buffer, buf_size); | 479 ensure_decimal_point(buffer, buf_size); |
499 | 480 |
500 /* If format_char is 'n', add the thousands grouping. */ | |
501 if (format_char == 'n') | |
502 if (!add_thousands_grouping(buffer, buf_size)) | |
503 return NULL; | |
504 | |
505 return buffer; | 481 return buffer; |
506 } | 482 } |
507 | 483 |
508 double | 484 #ifdef PY_NO_SHORT_FLOAT_REPR |
509 PyOS_ascii_atof(const char *nptr) | 485 |
| 486 /* The fallback code to use if _Py_dg_dtoa is not available. */ |
| 487 |
| 488 PyAPI_FUNC(char *) PyOS_double_to_string(double val, |
| 489 char format_code, |
| 490 int precision, |
| 491 int flags, |
| 492 int *type) |
510 { | 493 { |
511 » return PyOS_ascii_strtod(nptr, NULL); | 494 » char buf[128]; |
| 495 » char format[32]; |
| 496 » Py_ssize_t len; |
| 497 » char *result; |
| 498 » char *p; |
| 499 » int t; |
| 500 » int upper = 0; |
| 501 |
| 502 » /* Validate format_code, and map upper and lower case */ |
| 503 » switch (format_code) { |
| 504 » case 'e': /* exponent */ |
| 505 » case 'f': /* fixed */ |
| 506 » case 'g': /* general */ |
| 507 » » break; |
| 508 » case 'E': |
| 509 » » upper = 1; |
| 510 » » format_code = 'e'; |
| 511 » » break; |
| 512 » case 'F': |
| 513 » » upper = 1; |
| 514 » » format_code = 'f'; |
| 515 » » break; |
| 516 » case 'G': |
| 517 » » upper = 1; |
| 518 » » format_code = 'g'; |
| 519 » » break; |
| 520 » case 'r': /* repr format */ |
| 521 » » /* Supplied precision is unused, must be 0. */ |
| 522 » » if (precision != 0) { |
| 523 » » » PyErr_BadInternalCall(); |
| 524 » » » return NULL; |
| 525 » » } |
| 526 » » precision = 17; |
| 527 » » format_code = 'g'; |
| 528 » » break; |
| 529 » case 's': /* str format */ |
| 530 » » /* Supplied precision is unused, must be 0. */ |
| 531 » » if (precision != 0) { |
| 532 » » » PyErr_BadInternalCall(); |
| 533 » » » return NULL; |
| 534 » » } |
| 535 » » precision = 12; |
| 536 » » format_code = 'g'; |
| 537 » » break; |
| 538 » default: |
| 539 » » PyErr_BadInternalCall(); |
| 540 » » return NULL; |
| 541 » } |
| 542 |
| 543 » /* Handle nan and inf. */ |
| 544 » if (Py_IS_NAN(val)) { |
| 545 » » strcpy(buf, "nan"); |
| 546 » » t = Py_DTST_NAN; |
| 547 » } else if (Py_IS_INFINITY(val)) { |
| 548 » » if (copysign(1., val) == 1.) |
| 549 » » » strcpy(buf, "inf"); |
| 550 » » else |
| 551 » » » strcpy(buf, "-inf"); |
| 552 » » t = Py_DTST_INFINITE; |
| 553 » } else { |
| 554 » » t = Py_DTST_FINITE; |
| 555 |
| 556 |
| 557 » » if (flags & Py_DTSF_ADD_DOT_0) |
| 558 » » » format_code = 'Z'; |
| 559 |
| 560 » » PyOS_snprintf(format, 32, "%%%s.%i%c", (flags & Py_DTSF_ALT ? "#
" : ""), precision, format_code); |
| 561 » » PyOS_ascii_formatd(buf, sizeof(buf), format, val); |
| 562 » } |
| 563 |
| 564 » len = strlen(buf); |
| 565 |
| 566 » /* Add 1 for the trailing 0 byte. |
| 567 » Add 1 because we might need to make room for the sign. |
| 568 » */ |
| 569 » result = PyMem_Malloc(len + 2); |
| 570 » if (result == NULL) { |
| 571 » » PyErr_NoMemory(); |
| 572 » » return NULL; |
| 573 » } |
| 574 » p = result; |
| 575 |
| 576 » /* Never add sign for nan/inf, even if asked. */ |
| 577 » if (flags & Py_DTSF_SIGN && buf[0] != '-' && t == Py_DTST_FINITE) |
| 578 » » *p++ = '+'; |
| 579 |
| 580 » strcpy(p, buf); |
| 581 |
| 582 » if (upper) { |
| 583 » » /* Convert to upper case. */ |
| 584 » » char *p1; |
| 585 » » for (p1 = p; *p1; p1++) |
| 586 » » » *p1 = toupper(*p1); |
| 587 » } |
| 588 |
| 589 » if (type) |
| 590 » » *type = t; |
| 591 » return result; |
512 } | 592 } |
513 | 593 |
| 594 #else |
| 595 |
| 596 /* _Py_dg_dtoa is available. */ |
514 | 597 |
515 /* I'm using a lookup table here so that I don't have to invent a non-locale | 598 /* I'm using a lookup table here so that I don't have to invent a non-locale |
516 specific way to convert to uppercase */ | 599 specific way to convert to uppercase */ |
517 #define OFS_INF 0 | 600 #define OFS_INF 0 |
518 #define OFS_NAN 1 | 601 #define OFS_NAN 1 |
519 #define OFS_E 2 | 602 #define OFS_E 2 |
520 | 603 |
521 /* The lengths of these are known to the code below, so don't change them */ | 604 /* The lengths of these are known to the code below, so don't change them */ |
522 static char *lc_float_strings[] = { | 605 static char *lc_float_strings[] = { |
523 "inf", | 606 "inf", |
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
881 precision = 12; | 964 precision = 12; |
882 break; | 965 break; |
883 } | 966 } |
884 | 967 |
885 return format_float_short(val, lc_format_code, mode, precision, | 968 return format_float_short(val, lc_format_code, mode, precision, |
886 flags & Py_DTSF_SIGN, | 969 flags & Py_DTSF_SIGN, |
887 flags & Py_DTSF_ADD_DOT_0, | 970 flags & Py_DTSF_ADD_DOT_0, |
888 flags & Py_DTSF_ALT, | 971 flags & Py_DTSF_ALT, |
889 float_strings, type); | 972 float_strings, type); |
890 } | 973 } |
| 974 #endif /* ifdef PY_NO_SHORT_FLOAT_REPR */ |
LEFT | RIGHT |