Skip to content

Commit

Permalink
Change detection of double 0.0 to use BitConverter.DoubleToInt64Bits
Browse files Browse the repository at this point in the history
Underneath BitConverter just casts 64bit double to a 64bit int with the same bit pattern, making it a simpler operation.

(cherry picked from commit 4d439ab)
  • Loading branch information
VSadov authored and agocke committed Jul 29, 2015
1 parent d4a181f commit c6a0c45
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Compilers/Core/Portable/ConstantValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public static ConstantValue Create(bool value)

public static ConstantValue Create(float value)
{
if (value == 0 && 1 / value > 0)
if (BitConverter.DoubleToInt64Bits(value) == 0)
{
return ConstantValueDefault.Single;
}
Expand All @@ -246,7 +246,7 @@ public static ConstantValue Create(float value)

public static ConstantValue CreateSingle(double value)
{
if (value == 0 && 1 / value > 0)
if (BitConverter.DoubleToInt64Bits(value) == 0)
{
return ConstantValueDefault.Single;
}
Expand All @@ -260,7 +260,7 @@ public static ConstantValue CreateSingle(double value)

public static ConstantValue Create(double value)
{
if (value == 0 && 1 / value > 0)
if (BitConverter.DoubleToInt64Bits(value) == 0)
{
return ConstantValueDefault.Double;
}
Expand Down

0 comments on commit c6a0c45

Please sign in to comment.