|
| 1 | +const __muloti4 = @import("muloti4.zig").__muloti4; |
| 2 | +const assert = @import("std").debug.assert; |
| 3 | + |
| 4 | +fn test__muloti4(a: i128, b: i128, expected: i128, expected_overflow: c_int) void { |
| 5 | + var overflow: c_int = undefined; |
| 6 | + const x = __muloti4(a, b, &overflow); |
| 7 | + assert(overflow == expected_overflow and (expected_overflow != 0 or x == expected)); |
| 8 | +} |
| 9 | + |
| 10 | +test "muloti4" { |
| 11 | + test__muloti4(0, 0, 0, 0); |
| 12 | + test__muloti4(0, 1, 0, 0); |
| 13 | + test__muloti4(1, 0, 0, 0); |
| 14 | + test__muloti4(0, 10, 0, 0); |
| 15 | + test__muloti4(10, 0, 0, 0); |
| 16 | + |
| 17 | + test__muloti4(0, 81985529216486895, 0, 0); |
| 18 | + test__muloti4(81985529216486895, 0, 0, 0); |
| 19 | + |
| 20 | + test__muloti4(0, -1, 0, 0); |
| 21 | + test__muloti4(-1, 0, 0, 0); |
| 22 | + test__muloti4(0, -10, 0, 0); |
| 23 | + test__muloti4(-10, 0, 0, 0); |
| 24 | + test__muloti4(0, -81985529216486895, 0, 0); |
| 25 | + test__muloti4(-81985529216486895, 0, 0, 0); |
| 26 | + |
| 27 | + test__muloti4(3037000499, 3037000499, 9223372030926249001, 0); |
| 28 | + test__muloti4(-3037000499, 3037000499, -9223372030926249001, 0); |
| 29 | + test__muloti4(3037000499, -3037000499, -9223372030926249001, 0); |
| 30 | + test__muloti4(-3037000499, -3037000499, 9223372030926249001, 0); |
| 31 | + |
| 32 | + test__muloti4(4398046511103, 2097152, 9223372036852678656, 0); |
| 33 | + test__muloti4(-4398046511103, 2097152, -9223372036852678656, 0); |
| 34 | + test__muloti4(4398046511103, -2097152, -9223372036852678656, 0); |
| 35 | + test__muloti4(-4398046511103, -2097152, 9223372036852678656, 0); |
| 36 | + |
| 37 | + test__muloti4(2097152, 4398046511103, 9223372036852678656, 0); |
| 38 | + test__muloti4(-2097152, 4398046511103, -9223372036852678656, 0); |
| 39 | + test__muloti4(2097152, -4398046511103, -9223372036852678656, 0); |
| 40 | + test__muloti4(-2097152, -4398046511103, 9223372036852678656, 0); |
| 41 | + |
| 42 | + test__muloti4(@bitCast(i128, u128(0x00000000000000B504F333F9DE5BE000)), @bitCast(i128, u128(0x000000000000000000B504F333F9DE5B)), @bitCast(i128, u128(0x7FFFFFFFFFFFF328DF915DA296E8A000)), 0); |
| 43 | + test__muloti4(@bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), -2, @bitCast(i128, u128(0x80000000000000000000000000000001)), 1); |
| 44 | + test__muloti4(-2, @bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, u128(0x80000000000000000000000000000001)), 1); |
| 45 | + |
| 46 | + test__muloti4(@bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), -1, @bitCast(i128, u128(0x80000000000000000000000000000001)), 0); |
| 47 | + test__muloti4(-1, @bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, u128(0x80000000000000000000000000000001)), 0); |
| 48 | + test__muloti4(@bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0, 0, 0); |
| 49 | + test__muloti4(0, @bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0, 0); |
| 50 | + test__muloti4(@bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 1, @bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0); |
| 51 | + test__muloti4(1, @bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0); |
| 52 | + test__muloti4(@bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 2, @bitCast(i128, u128(0x80000000000000000000000000000001)), 1); |
| 53 | + test__muloti4(2, @bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), @bitCast(i128, u128(0x80000000000000000000000000000001)), 1); |
| 54 | + |
| 55 | + test__muloti4(@bitCast(i128, u128(0x80000000000000000000000000000000)), -2, @bitCast(i128, u128(0x80000000000000000000000000000000)), 1); |
| 56 | + test__muloti4(-2, @bitCast(i128, u128(0x80000000000000000000000000000000)), @bitCast(i128, u128(0x80000000000000000000000000000000)), 1); |
| 57 | + test__muloti4(@bitCast(i128, u128(0x80000000000000000000000000000000)), -1, @bitCast(i128, u128(0x80000000000000000000000000000000)), 1); |
| 58 | + test__muloti4(-1, @bitCast(i128, u128(0x80000000000000000000000000000000)), @bitCast(i128, u128(0x80000000000000000000000000000000)), 1); |
| 59 | + test__muloti4(@bitCast(i128, u128(0x80000000000000000000000000000000)), 0, 0, 0); |
| 60 | + test__muloti4(0, @bitCast(i128, u128(0x80000000000000000000000000000000)), 0, 0); |
| 61 | + test__muloti4(@bitCast(i128, u128(0x80000000000000000000000000000000)), 1, @bitCast(i128, u128(0x80000000000000000000000000000000)), 0); |
| 62 | + test__muloti4(1, @bitCast(i128, u128(0x80000000000000000000000000000000)), @bitCast(i128, u128(0x80000000000000000000000000000000)), 0); |
| 63 | + test__muloti4(@bitCast(i128, u128(0x80000000000000000000000000000000)), 2, @bitCast(i128, u128(0x80000000000000000000000000000000)), 1); |
| 64 | + test__muloti4(2, @bitCast(i128, u128(0x80000000000000000000000000000000)), @bitCast(i128, u128(0x80000000000000000000000000000000)), 1); |
| 65 | + |
| 66 | + test__muloti4(@bitCast(i128, u128(0x80000000000000000000000000000001)), -2, @bitCast(i128, u128(0x80000000000000000000000000000001)), 1); |
| 67 | + test__muloti4(-2, @bitCast(i128, u128(0x80000000000000000000000000000001)), @bitCast(i128, u128(0x80000000000000000000000000000001)), 1); |
| 68 | + test__muloti4(@bitCast(i128, u128(0x80000000000000000000000000000001)), -1, @bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0); |
| 69 | + test__muloti4(-1, @bitCast(i128, u128(0x80000000000000000000000000000001)), @bitCast(i128, u128(0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)), 0); |
| 70 | + test__muloti4(@bitCast(i128, u128(0x80000000000000000000000000000001)), 0, 0, 0); |
| 71 | + test__muloti4(0, @bitCast(i128, u128(0x80000000000000000000000000000001)), 0, 0); |
| 72 | + test__muloti4(@bitCast(i128, u128(0x80000000000000000000000000000001)), 1, @bitCast(i128, u128(0x80000000000000000000000000000001)), 0); |
| 73 | + test__muloti4(1, @bitCast(i128, u128(0x80000000000000000000000000000001)), @bitCast(i128, u128(0x80000000000000000000000000000001)), 0); |
| 74 | + test__muloti4(@bitCast(i128, u128(0x80000000000000000000000000000001)), 2, @bitCast(i128, u128(0x80000000000000000000000000000000)), 1); |
| 75 | + test__muloti4(2, @bitCast(i128, u128(0x80000000000000000000000000000001)), @bitCast(i128, u128(0x80000000000000000000000000000000)), 1); |
| 76 | +} |
0 commit comments