add decimal comparisons and conversions to wasm backend

This commit is contained in:
Folkert 2023-09-13 22:28:39 +02:00
parent d7bc03c589
commit 5bcfd91f3a
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
4 changed files with 134 additions and 7 deletions

View file

@ -1122,7 +1122,20 @@ pub fn toStr(arg: RocDec) callconv(.C) RocStr {
}
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");
if (@call(.{ .modifier = always_inline }, RocDec.fromF64, .{arg})) |dec| {
return dec.num;
} else {
@panic("TODO runtime exception failing convert f64 to RocDec");
}
}
pub fn fromF32C(arg_f32: f32) callconv(.C) i128 {
const arg_f64 = arg_f32;
if (@call(.{ .modifier = always_inline }, RocDec.fromF64, .{arg_f64})) |dec| {
return dec.num;
} else {
@panic("TODO runtime exception failing convert f64 to RocDec");
}
}
pub fn exportFromInt(comptime T: type, comptime name: []const u8) void {

View file

@ -20,7 +20,6 @@ const dec = @import("dec.zig");
comptime {
exportDecFn(dec.fromStr, "from_str");
exportDecFn(dec.toStr, "to_str");
exportDecFn(dec.fromF64C, "from_f64");
exportDecFn(dec.fromU64C, "from_u64");
exportDecFn(dec.toI128, "to_i128");
exportDecFn(dec.eqC, "eq");
@ -43,6 +42,9 @@ comptime {
inline for (INTEGERS) |T| {
dec.exportFromInt(T, ROC_BUILTINS ++ ".dec.from_int.");
}
exportDecFn(dec.fromF32C, "from_float.f32");
exportDecFn(dec.fromF64C, "from_float.f64");
}
// List Module
@ -100,6 +102,19 @@ comptime {
exportNumFn(num.greaterThanU128, "greater_than.u128");
exportNumFn(num.greaterThanOrEqualU128, "greater_than_or_equal.u128");
exportNumFn(num.compareI128, "compare.i128");
exportNumFn(num.compareU128, "compare.u128");
exportNumFn(num.lessThanI128, "less_than.i128");
exportNumFn(num.lessThanOrEqualI128, "less_than_or_equal.i128");
exportNumFn(num.greaterThanI128, "greater_than.i128");
exportNumFn(num.greaterThanOrEqualI128, "greater_than_or_equal.i128");
exportNumFn(num.lessThanU128, "less_than.u128");
exportNumFn(num.lessThanOrEqualU128, "less_than_or_equal.u128");
exportNumFn(num.greaterThanU128, "greater_than.u128");
exportNumFn(num.greaterThanOrEqualU128, "greater_than_or_equal.u128");
inline for (INTEGERS) |T, i| {
num.exportPow(T, ROC_BUILTINS ++ "." ++ NUM ++ ".pow_int.");
num.exportDivCeil(T, ROC_BUILTINS ++ "." ++ NUM ++ ".div_ceil.");