subvdi3.zig (932B) - Raw
1 const subv = @import("subo.zig"); 2 const common = @import("./common.zig"); 3 const testing = @import("std").testing; 4 5 pub const panic = common.panic; 6 7 comptime { 8 @export(&__subvdi3, .{ .name = "__subvdi3", .linkage = common.linkage, .visibility = common.visibility }); 9 } 10 11 pub fn __subvdi3(a: i64, b: i64) callconv(.c) i64 { 12 var overflow: c_int = 0; 13 const sum = subv.__subodi4(a, b, &overflow); 14 if (overflow != 0) @panic("compiler-rt: integer overflow"); 15 return sum; 16 } 17 18 test "subvdi3" { 19 // min i64 = -9223372036854775808 20 // max i64 = 9223372036854775807 21 // TODO write panic handler for testing panics 22 // try test__subvdi3(-9223372036854775808, -1, -1); // panic 23 // try test__addvdi3(9223372036854775807, 1, 1); // panic 24 try testing.expectEqual(-9223372036854775808, __subvdi3(-9223372036854775807, 1)); 25 try testing.expectEqual(9223372036854775807, __subvdi3(9223372036854775806, -1)); 26 }