zig/lib/compiler_rt/divti3_test.zig

22 lines
846 B
Zig
Raw Normal View History

2018-06-13 11:25:04 +01:00
const __divti3 = @import("divti3.zig").__divti3;
const testing = @import("std").testing;
2018-06-13 11:25:04 +01:00
fn test__divti3(a: i128, b: i128, expected: i128) !void {
2018-06-13 11:25:04 +01:00
const x = __divti3(a, b);
2021-05-04 18:47:26 +01:00
try testing.expect(x == expected);
2018-06-13 11:25:04 +01:00
}
test "divti3" {
try test__divti3(0, 1, 0);
try test__divti3(0, -1, 0);
try test__divti3(2, 1, 2);
try test__divti3(2, -1, -2);
try test__divti3(-2, 1, -2);
try test__divti3(-2, -1, 2);
2018-06-13 11:25:04 +01:00
try test__divti3(@bitCast(i128, @as(u128, 0x8 << 124)), 1, @bitCast(i128, @as(u128, 0x8 << 124)));
try test__divti3(@bitCast(i128, @as(u128, 0x8 << 124)), -1, @bitCast(i128, @as(u128, 0x8 << 124)));
try test__divti3(@bitCast(i128, @as(u128, 0x8 << 124)), -2, @bitCast(i128, @as(u128, 0x4 << 124)));
try test__divti3(@bitCast(i128, @as(u128, 0x8 << 124)), 2, @bitCast(i128, @as(u128, 0xc << 124)));
2018-06-13 11:25:04 +01:00
}