Make double min/max follow DXIL FMin/FMax
dxc lowers double min/max to dx.op.binary.f64 opcodes 36/35 (FMin/FMax), the same operations as float, so Math.Min/Math.Max (NaN-propagating) was the wrong rule. Double min/max now use the float formulas, with NaN and signed-zero assertions beside the float ones. Tracked Unity DLL rebuilt. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
08e213dd7c
commit
19e23db211
4 changed files with 11 additions and 2 deletions
|
|
@ -402,8 +402,9 @@ public static partial class math
|
|||
public static float3 atan2(float3 y, float3 x) => new(atan2(y.x, x.x), atan2(y.y, x.y), atan2(y.z, x.z));
|
||||
public static float4 atan2(float4 y, float4 x) => new(atan2(y.x, x.x), atan2(y.y, x.y), atan2(y.z, x.z), atan2(y.w, x.w));
|
||||
|
||||
public static double min(double left, double right) => Math.Min(left, right);
|
||||
public static double max(double left, double right) => Math.Max(left, right);
|
||||
// DXIL FMin/FMax take double overloads with the same rules as float (see min/max above).
|
||||
public static double min(double left, double right) => left < right || double.IsNaN(right) ? left : right;
|
||||
public static double max(double left, double right) => left >= right || double.IsNaN(right) ? left : right;
|
||||
|
||||
public static bool any(bool2 value) => value.x || value.y;
|
||||
public static bool any(bool3 value) => value.x || value.y || value.z;
|
||||
|
|
|
|||
|
|
@ -178,6 +178,14 @@ public sealed class HlslSemanticsTests
|
|||
Assert.Equal(Bits(-0.0f), Bits(math.max(-0.0f, 0.0f)));
|
||||
Assert.Equal(Bits(0.0f), Bits(math.min(-0.0f, 0.0f)));
|
||||
Assert.Equal(Bits(0.0f), Bits(math.saturate(-0.0f)));
|
||||
Assert.Equal(1.0, math.min(double.NaN, 1.0));
|
||||
Assert.Equal(1.0, math.min(1.0, double.NaN));
|
||||
Assert.Equal(1.0, math.max(double.NaN, 1.0));
|
||||
Assert.Equal(1.0, math.max(1.0, double.NaN));
|
||||
Assert.True(double.IsNaN(math.max(double.NaN, double.NaN)));
|
||||
static long DoubleBits(double value) => BitConverter.DoubleToInt64Bits(value);
|
||||
Assert.Equal(DoubleBits(-0.0), DoubleBits(math.max(-0.0, 0.0)));
|
||||
Assert.Equal(DoubleBits(0.0), DoubleBits(math.min(-0.0, 0.0)));
|
||||
|
||||
Assert.Equal(0, math.sign(float.NaN));
|
||||
Assert.Equal(-1, math.sign(-0.5f));
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
Loading…
Reference in a new issue