mirror of
https://github.com/roc-lang/roc.git
synced 2025-07-19 04:25:03 +00:00
Add support for Num.abs to Dec type
This commit is contained in:
parent
8f210241ab
commit
fa65d89a3c
4 changed files with 56 additions and 47 deletions
|
@ -235,6 +235,11 @@ pub const RocDec = extern struct {
|
|||
return if (negated) |n| .{ .num = n } else null;
|
||||
}
|
||||
|
||||
pub fn abs(self: RocDec) !RocDec {
|
||||
const absolute = try math.absInt(self.num);
|
||||
return RocDec{ .num = absolute };
|
||||
}
|
||||
|
||||
pub fn addWithOverflow(self: RocDec, other: RocDec) WithOverflow(RocDec) {
|
||||
var answer: i128 = undefined;
|
||||
const overflowed = @addWithOverflow(i128, self.num, other.num, &answer);
|
||||
|
@ -1244,6 +1249,11 @@ pub fn negateC(arg: RocDec) callconv(.C) i128 {
|
|||
return if (@call(.{ .modifier = always_inline }, RocDec.negate, .{arg})) |dec| dec.num else @panic("TODO overflow for negating RocDec");
|
||||
}
|
||||
|
||||
pub fn absC(arg: RocDec) callconv(.C) i128 {
|
||||
var result = @call(.{ .modifier = always_inline }, RocDec.abs, .{arg}) catch @panic("TODO overflow for calling absolute value on RocDec");
|
||||
return result.num;
|
||||
}
|
||||
|
||||
pub fn addC(arg1: RocDec, arg2: RocDec) callconv(.C) WithOverflow(RocDec) {
|
||||
return @call(.{ .modifier = always_inline }, RocDec.addWithOverflow, .{ arg1, arg2 });
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue