diff options
| author | Robin Voetter <robin@voetter.nl> | 2023-10-14 12:52:31 +0200 |
|---|---|---|
| committer | Robin Voetter <robin@voetter.nl> | 2023-10-15 14:00:32 +0200 |
| commit | 9c20449cc5be5da0458556e143980b40d51e8776 (patch) | |
| tree | cfa8ddf891494b237ba3e9a5268f222c90821c0f /test/behavior/maximum_minimum.zig | |
| parent | 2fe16e072ac447de5826ee436f50f73f56876ff9 (diff) | |
| download | zig-9c20449cc5be5da0458556e143980b40d51e8776.tar.gz zig-9c20449cc5be5da0458556e143980b40d51e8776.zip | |
wasm: lower min/max for floats to compiler_rt
The min and max builtins in Zig have some intricate behavior
related to floats, that is not replicated with the min and max
wasm instructions or using simple select operations. By lowering
these instructions to compiler_rt, handling around NaNs is done
correctly.
See also https://github.com/WebAssembly/design/issues/214
Diffstat (limited to 'test/behavior/maximum_minimum.zig')
| -rw-r--r-- | test/behavior/maximum_minimum.zig | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/test/behavior/maximum_minimum.zig b/test/behavior/maximum_minimum.zig index 0b9ca8c636..ecc32a33f6 100644 --- a/test/behavior/maximum_minimum.zig +++ b/test/behavior/maximum_minimum.zig @@ -123,6 +123,12 @@ test "@min/max for floats" { try expectEqual(x, @min(y, x)); try expectEqual(y, @max(x, y)); try expectEqual(y, @max(y, x)); + + if (T != comptime_float) { + var nan: T = std.math.nan(T); + try expectEqual(y, @max(nan, y)); + try expectEqual(y, @max(y, nan)); + } } }; |
