@@ -913,8 +913,6 @@ internal static bool TryParseFloat(string text, out double res, bool replaceUnic
913913 return false ;
914914 }
915915 res = ParseFloatNoCatch ( text , replaceUnicode : replaceUnicode ) ;
916- } catch ( OverflowException ) {
917- res = text . lstrip ( ) . StartsWith ( "-" , StringComparison . Ordinal ) ? Double . NegativeInfinity : Double . PositiveInfinity ;
918916 } catch ( FormatException ) {
919917 res = default ;
920918 return false ;
@@ -923,19 +921,15 @@ internal static bool TryParseFloat(string text, out double res, bool replaceUnic
923921 }
924922
925923 public static double ParseFloat ( string text ) {
926- try {
927- //
928- // Strings that end with '\0' is the specific case that CLR libraries allow,
929- // however Python doesn't. Since we use CLR floating point number parser,
930- // we must check explicitly for the strings that end with '\0'
931- //
932- if ( text != null && text . Length > 0 && text [ text . Length - 1 ] == '\0 ' ) {
933- throw PythonOps . ValueError ( "null byte in float literal" ) ;
934- }
935- return ParseFloatNoCatch ( text ) ;
936- } catch ( OverflowException ) {
937- return text . lstrip ( ) . StartsWith ( "-" , StringComparison . Ordinal ) ? Double . NegativeInfinity : Double . PositiveInfinity ;
924+ //
925+ // Strings that end with '\0' is the specific case that CLR libraries allow,
926+ // however Python doesn't. Since we use CLR floating point number parser,
927+ // we must check explicitly for the strings that end with '\0'
928+ //
929+ if ( text != null && text . Length > 0 && text [ text . Length - 1 ] == '\0 ' ) {
930+ throw PythonOps . ValueError ( "null byte in float literal" ) ;
938931 }
932+ return ParseFloatNoCatch ( text ) ;
939933 }
940934
941935 private static double ParseFloatNoCatch ( string text , bool replaceUnicode = true ) {
@@ -955,7 +949,12 @@ private static double ParseFloatNoCatch(string text, bool replaceUnicode = true)
955949 return double . NegativeInfinity ;
956950 default :
957951 // pass NumberStyles to disallow ,'s in float strings.
958- double res = double . Parse ( s , NumberStyles . Float , System . Globalization . CultureInfo . InvariantCulture ) ;
952+ double res ;
953+ try {
954+ res = double . Parse ( s , NumberStyles . Float , System . Globalization . CultureInfo . InvariantCulture ) ;
955+ } catch ( OverflowException ) {
956+ res = text . lstrip ( ) . StartsWith ( "-" , StringComparison . Ordinal ) ? Double . NegativeInfinity : Double . PositiveInfinity ;
957+ }
959958 return ( res == 0.0 && text . lstrip ( ) . StartsWith ( "-" , StringComparison . Ordinal ) ) ? DoubleOps . NegativeZero : res ;
960959 }
961960 }
@@ -1005,7 +1004,7 @@ public static Complex ParseComplex(string s) {
10051004 int len = text . Length ;
10061005 var idx = text . IndexOf ( 'j' ) ;
10071006 if ( idx == - 1 ) {
1008- return MathUtils . MakeReal ( ParseFloatNoCatch ( text ) ) ;
1007+ return MathUtils . MakeReal ( ParseFloat ( text ) ) ;
10091008 } else if ( idx == len - 1 ) {
10101009 // last sign delimits real and imaginary...
10111010 int signPos = text . LastIndexOfAny ( signs ) ;
@@ -1020,7 +1019,7 @@ public static Complex ParseComplex(string s) {
10201019
10211020 // no real component
10221021 if ( signPos < 0 ) {
1023- return MathUtils . MakeImaginary ( ( len == 1 ) ? 1 : ParseFloatNoCatch ( text . Substring ( 0 , len - 1 ) ) ) ;
1022+ return MathUtils . MakeImaginary ( ( len == 1 ) ? 1 : ParseFloat ( text . Substring ( 0 , len - 1 ) ) ) ;
10241023 }
10251024
10261025 string real = text . Substring ( 0 , signPos ) ;
@@ -1029,12 +1028,10 @@ public static Complex ParseComplex(string s) {
10291028 imag += "1" ; // convert +/- to +1/-1
10301029 }
10311030
1032- return new Complex ( String . IsNullOrEmpty ( real ) ? 0 : ParseFloatNoCatch ( real ) , ParseFloatNoCatch ( imag ) ) ;
1031+ return new Complex ( String . IsNullOrEmpty ( real ) ? 0 : ParseFloat ( real ) , ParseFloat ( imag ) ) ;
10331032 } else {
10341033 throw ExnMalformed ( ) ;
10351034 }
1036- } catch ( OverflowException ) {
1037- throw PythonOps . ValueError ( "complex() literal too large to convert" ) ;
10381035 } catch {
10391036 throw ExnMalformed ( ) ;
10401037 }
0 commit comments