diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/WellKnownConstants.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/WellKnownConstants.cs index b77d38dfd..c26aeb947 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/WellKnownConstants.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/WellKnownConstants.cs @@ -202,5 +202,10 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty public const double Double_Negated_E = -Math.E; public const double Double_Negated_BeforeE = -2.7182818284590446; public const double Double_Negated_AfterE = -2.7182818284590455; + + // Values of either sign whose ratio to PI or E is outside the range expressible as + // a fraction must be left alone rather than run through the approximation. + public const double Double_TooLargeForFraction = 3085105840164255.5; + public const double Double_Negated_TooLargeForFraction = -3085105840164255.5; } } diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/TypeSystemAstBuilder.cs b/ICSharpCode.Decompiler/CSharp/Syntax/TypeSystemAstBuilder.cs index ad07cb6fc..2d8654a18 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/TypeSystemAstBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/TypeSystemAstBuilder.cs @@ -1724,7 +1724,10 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax // we just keep the last partial product of these matrices. static (long Num, long Den) FractionApprox(double value, int maxDenominator) { - if (value > 0x7FFFFFFF) + // The range check has to be on the magnitude: the sign is stripped below, so a + // large negative value would otherwise reach the continued-fraction loop and + // overflow the terms it accumulates. + if (Math.Abs(value) > 0x7FFFFFFF) return (0, 0); double startValue = value;