mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 14:54:47 +00:00
[WIP] Add Dec/Decimal builtin types
This commit is contained in:
parent
07dea4ee04
commit
4d6e5a1a4f
15 changed files with 160 additions and 16 deletions
|
@ -2,9 +2,10 @@ const std = @import("std");
|
|||
const str = @import("str.zig");
|
||||
|
||||
const math = std.math;
|
||||
const always_inline = std.builtin.CallOptions.Modifier.always_inline;
|
||||
const RocStr = str.RocStr;
|
||||
|
||||
pub const RocDec = struct {
|
||||
pub const RocDec = extern struct {
|
||||
num: i128,
|
||||
|
||||
pub const decimal_places: comptime u5 = 18;
|
||||
|
@ -953,3 +954,11 @@ test "div: 10 / 3" {
|
|||
|
||||
try expectEqual(res, numer.div(denom));
|
||||
}
|
||||
|
||||
// exports
|
||||
|
||||
const FromStrResult = extern struct { dec: RocDec, is_ok: bool };
|
||||
|
||||
pub fn fromStrC(arg: RocStr, output: *FromStrResult) callconv(.C) void {
|
||||
output.* = if (@call(.{ .modifier = always_inline }, RocDec.fromStr, .{arg})) |dec| .{ .dec = dec, .is_ok = true } else .{ .dec = RocDec.one_point_zero, .is_ok = false };
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue