diff options
| author | LemonBoy <thatlemon@gmail.com> | 2021-10-24 17:11:43 +0200 |
|---|---|---|
| committer | LemonBoy <thatlemon@gmail.com> | 2021-10-24 17:11:43 +0200 |
| commit | 811766e1cf0ad2fad73fbb82690969ce430ba1a5 (patch) | |
| tree | 5f550e0115e5dcc9f6178be03c0dc8af63e86d58 /test/behavior/math.zig | |
| parent | 94879506ea8fe51310f38b3db1bc1ea1e71a4389 (diff) | |
| download | zig-811766e1cf0ad2fad73fbb82690969ce430ba1a5.tar.gz zig-811766e1cf0ad2fad73fbb82690969ce430ba1a5.zip | |
stage1/stage2: Simplify divTrunc impl
According to the documentation, `divTrunc` is "Truncated division.
Rounds toward zero". Lower it as a straightforward fdiv + trunc sequence
to make it behave as expected with mixed positive/negative operands.
Closes #10001
Diffstat (limited to 'test/behavior/math.zig')
| -rw-r--r-- | test/behavior/math.zig | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/test/behavior/math.zig b/test/behavior/math.zig index 158e144f5d..1073183a3c 100644 --- a/test/behavior/math.zig +++ b/test/behavior/math.zig @@ -282,12 +282,20 @@ fn testDivision() !void { try expect(divTrunc(i32, 5, 3) == 1); try expect(divTrunc(i32, -5, 3) == -1); + try expect(divTrunc(i32, 9, -10) == 0); + try expect(divTrunc(i32, -9, 10) == 0); try expect(divTrunc(f16, 5.0, 3.0) == 1.0); try expect(divTrunc(f16, -5.0, 3.0) == -1.0); + try expect(divTrunc(f16, 9.0, -10.0) == 0.0); + try expect(divTrunc(f16, -9.0, 10.0) == 0.0); try expect(divTrunc(f32, 5.0, 3.0) == 1.0); try expect(divTrunc(f32, -5.0, 3.0) == -1.0); + try expect(divTrunc(f32, 9.0, -10.0) == 0.0); + try expect(divTrunc(f32, -9.0, 10.0) == 0.0); try expect(divTrunc(f64, 5.0, 3.0) == 1.0); try expect(divTrunc(f64, -5.0, 3.0) == -1.0); + try expect(divTrunc(f64, 9.0, -10.0) == 0.0); + try expect(divTrunc(f64, -9.0, 10.0) == 0.0); try expect(divTrunc(i32, 10, 12) == 0); try expect(divTrunc(i32, -14, 12) == -1); try expect(divTrunc(i32, -2, 12) == 0); |
