@@ -746,18 +746,15 @@ PyAPI_FUNC(char *) PyOS_double_to_string(double val,
746746 PyErr_BadInternalCall ();
747747 return NULL ;
748748 }
749+ /* The repr() precision (17 significant decimal digits) is the
750+ minimal number that is guaranteed to have enough precision
751+ so that if the number is read back in the exact same binary
752+ value is recreated. This is true for IEEE floating point
753+ by design, and also happens to work for all other modern
754+ hardware. */
749755 precision = 17 ;
750756 format_code = 'g' ;
751757 break ;
752- case 's' : /* str format */
753- /* Supplied precision is unused, must be 0. */
754- if (precision != 0 ) {
755- PyErr_BadInternalCall ();
756- return NULL ;
757- }
758- precision = 12 ;
759- format_code = 'g' ;
760- break ;
761758 default :
762759 PyErr_BadInternalCall ();
763760 return NULL ;
@@ -889,18 +886,19 @@ static char *uc_float_strings[] = {
889886
890887 Arguments:
891888 d is the double to be converted
892- format_code is one of 'e', 'f', 'g', 'r' or 's'. 'e', 'f' and 'g'
893- correspond to '%e', '%f' and '%g'; 'r' and 's' correspond
894- to repr and str.
889+ format_code is one of 'e', 'f', 'g', 'r'. 'e', 'f' and 'g'
890+ correspond to '%e', '%f' and '%g'; 'r' corresponds to repr.
895891 mode is one of '0', '2' or '3', and is completely determined by
896- format_code: 'e', 'g' and 's ' use mode 2; 'f' mode 3, 'r' mode 0.
892+ format_code: 'e' and 'g ' use mode 2; 'f' mode 3, 'r' mode 0.
897893 precision is the desired precision
898894 always_add_sign is nonzero if a '+' sign should be included for positive
899895 numbers
900896 add_dot_0_if_integer is nonzero if integers in non-exponential form
901- should have ".0" added. Only applies to format codes 'r', 's', and 'g'.
897+ should have ".0" added. Only applies to format codes 'r' and 'g'.
902898 use_alt_formatting is nonzero if alternative formatting should be
903- used. Only applies to format codes 'e', 'f' and 'g'.
899+ used. Only applies to format codes 'e', 'f' and 'g'. For code 'g',
900+ at most one of use_alt_formatting and add_dot_0_if_integer should
901+ be nonzero.
904902 type, if non-NULL, will be set to one of these constants to identify
905903 the type of the 'd' argument:
906904 Py_DTST_FINITE
@@ -1041,13 +1039,6 @@ format_float_short(double d, char format_code,
10411039 if (decpt <= -4 || decpt > 16 )
10421040 use_exp = 1 ;
10431041 break ;
1044- case 's' :
1045- /* if we're forcing a digit after the point, convert to
1046- exponential format at 1e11. If not, convert at 1e12. */
1047- if (decpt <= -4 || decpt >
1048- (add_dot_0_if_integer ? precision - 1 : precision ))
1049- use_exp = 1 ;
1050- break ;
10511042 default :
10521043 PyErr_BadInternalCall ();
10531044 goto exit ;
@@ -1220,17 +1211,6 @@ PyAPI_FUNC(char *) PyOS_double_to_string(double val,
12201211 }
12211212 break ;
12221213
1223- /* str format */
1224- case 's' :
1225- mode = 2 ;
1226- /* Supplied precision is unused, must be 0. */
1227- if (precision != 0 ) {
1228- PyErr_BadInternalCall ();
1229- return NULL ;
1230- }
1231- precision = 12 ;
1232- break ;
1233-
12341214 default :
12351215 PyErr_BadInternalCall ();
12361216 return NULL ;
0 commit comments