Implement hash for Dec

This commit is contained in:
Ayaz Hafiz 2023-05-26 11:32:59 -05:00
parent 0b475ae979
commit 3585d5bb5b
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
12 changed files with 44 additions and 6 deletions

View file

@ -209,6 +209,10 @@ pub const RocDec = extern struct {
return RocStr.init(&str_bytes, position);
}
pub fn toI128(self: RocDec) i128 {
return self.num;
}
pub fn eq(self: RocDec, other: RocDec) bool {
return self.num == other.num;
}
@ -1108,6 +1112,10 @@ pub fn fromF64C(arg: f64) callconv(.C) i128 {
return if (@call(.{ .modifier = always_inline }, RocDec.fromF64, .{arg})) |dec| dec.num else @panic("TODO runtime exception failing convert f64 to RocDec");
}
pub fn toI128(arg: RocDec) callconv(.C) i128 {
return @call(.{ .modifier = always_inline }, RocDec.toI128, .{arg});
}
pub fn eqC(arg1: RocDec, arg2: RocDec) callconv(.C) bool {
return @call(.{ .modifier = always_inline }, RocDec.eq, .{ arg1, arg2 });
}

View file

@ -16,6 +16,7 @@ comptime {
exportDecFn(dec.fromStr, "from_str");
exportDecFn(dec.toStr, "to_str");
exportDecFn(dec.fromF64C, "from_f64");
exportDecFn(dec.toI128, "to_i128");
exportDecFn(dec.eqC, "eq");
exportDecFn(dec.neqC, "neq");
exportDecFn(dec.negateC, "negate");