Browse Source

Merge pull request #1790 from Chicken-Bones/minuszero

Fix extra minus sign when formatting -0 on .NET Core 3.0
pull/1791/head
Daniel Grunwald 7 years ago committed by GitHub
parent
commit
31dbce2184
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      ICSharpCode.Decompiler/CSharp/OutputVisitor/TextWriterTokenWriter.cs

15
ICSharpCode.Decompiler/CSharp/OutputVisitor/TextWriterTokenWriter.cs

@ -298,15 +298,13 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
} }
return; return;
} }
if (f == 0 && 1 / f == float.NegativeInfinity) { var str = f.ToString("R", NumberFormatInfo.InvariantInfo) + "f";
if (f == 0 && 1 / f == float.NegativeInfinity && str[0] != '-') {
// negative zero is a special case // negative zero is a special case
// (again, not a primitive expression, but it's better to handle // (again, not a primitive expression, but it's better to handle
// the special case here than to do it in all code generators) // the special case here than to do it in all code generators)
textWriter.Write("-"); str = '-' + str;
column++;
Length++;
} }
var str = f.ToString("R", NumberFormatInfo.InvariantInfo) + "f";
column += str.Length; column += str.Length;
Length += str.Length; Length += str.Length;
textWriter.Write(str); textWriter.Write(str);
@ -334,14 +332,13 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
} }
return; return;
} }
if (f == 0 && 1 / f == double.NegativeInfinity) { string number = f.ToString("R", NumberFormatInfo.InvariantInfo);
if (f == 0 && 1 / f == double.NegativeInfinity && number[0] != '-') {
// negative zero is a special case // negative zero is a special case
// (again, not a primitive expression, but it's better to handle // (again, not a primitive expression, but it's better to handle
// the special case here than to do it in all code generators) // the special case here than to do it in all code generators)
textWriter.Write("-"); number = '-' + number;
Length++;
} }
string number = f.ToString("R", NumberFormatInfo.InvariantInfo);
if (number.IndexOf('.') < 0 && number.IndexOf('E') < 0) { if (number.IndexOf('.') < 0 && number.IndexOf('E') < 0) {
number += ".0"; number += ".0";
} }

Loading…
Cancel
Save