Skip to content

Commit

Permalink
Fixed emitting floating point constants in OpenCL (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
MoFtZ authored May 3, 2020
1 parent eee9e1b commit 6ea5345
Showing 1 changed file with 39 additions and 7 deletions.
46 changes: 39 additions & 7 deletions Src/ILGPU/Backends/OpenCL/CLCodeGenerator.Emitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -381,12 +381,28 @@ public void AppendConstant(ulong value)
public void AppendConstant(float value)
{
AppendArgument();
stringBuilder.Append(
value.ToString(CultureInfo.InvariantCulture));
if (value % 1.0f == 0.0f)
stringBuilder.Append(".0f");

if (float.IsNaN(value))
{
stringBuilder.Append("NAN");
}
else if (float.IsPositiveInfinity(value))
{
stringBuilder.Append("INFINITY");
}
else if (float.IsNegativeInfinity(value))
{
stringBuilder.Append("-INFINITY");
}
else
stringBuilder.Append('f');
{
stringBuilder.Append(
value.ToString(CultureInfo.InvariantCulture));
if (value % 1.0f == 0.0f)
stringBuilder.Append(".0f");
else
stringBuilder.Append('f');
}
}

/// <summary>
Expand All @@ -396,8 +412,24 @@ public void AppendConstant(float value)
public void AppendConstant(double value)
{
AppendArgument();
stringBuilder.Append(
value.ToString(CultureInfo.InvariantCulture));

if (double.IsNaN(value))
{
stringBuilder.Append("NAN");
}
else if (double.IsPositiveInfinity(value))
{
stringBuilder.Append("INFINITY");
}
else if (double.IsNegativeInfinity(value))
{
stringBuilder.Append("-INFINITY");
}
else
{
stringBuilder.Append(
value.ToString(CultureInfo.InvariantCulture));
}
}

/// <summary>
Expand Down

0 comments on commit 6ea5345

Please sign in to comment.