mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-04 12:18:19 +00:00
f32/f64toParts in repl only
This commit is contained in:
parent
64e9899cad
commit
473b8ef2d3
12 changed files with 72 additions and 6 deletions
|
@ -111,6 +111,8 @@ comptime {
|
|||
exportNumFn(num.lessThanOrEqualU128, "less_than_or_equal.u128");
|
||||
exportNumFn(num.greaterThanU128, "greater_than.u128");
|
||||
exportNumFn(num.greaterThanOrEqualU128, "greater_than_or_equal.u128");
|
||||
exportNumFn(num.f32ToParts, "f32_to_parts");
|
||||
exportNumFn(num.f64ToParts, "f64_to_parts");
|
||||
|
||||
inline for (INTEGERS, 0..) |T, i| {
|
||||
num.exportPow(T, ROC_BUILTINS ++ "." ++ NUM ++ ".pow_int.");
|
||||
|
|
|
@ -15,6 +15,18 @@ pub fn NumParseResult(comptime T: type) type {
|
|||
};
|
||||
}
|
||||
|
||||
pub const F32Parts = extern struct {
|
||||
fraction: u32,
|
||||
exponent: u8,
|
||||
sign: bool,
|
||||
};
|
||||
|
||||
pub const F64Parts = extern struct {
|
||||
fraction: u64,
|
||||
exponent: u16,
|
||||
sign: bool,
|
||||
};
|
||||
|
||||
pub const U256 = struct {
|
||||
hi: u128,
|
||||
lo: u128,
|
||||
|
@ -630,3 +642,21 @@ pub fn exportCountOneBits(comptime T: type, comptime name: []const u8) void {
|
|||
}.func;
|
||||
@export(f, .{ .name = name ++ @typeName(T), .linkage = .Strong });
|
||||
}
|
||||
|
||||
pub fn f32ToParts(self: f32) callconv(.C) F32Parts {
|
||||
const u32Value = @as(u32, @bitCast(self));
|
||||
return F32Parts{
|
||||
.fraction = u32Value & 0x7fffff,
|
||||
.exponent = @truncate(u32Value >> 23 & 0xff),
|
||||
.sign = u32Value >> 31 & 1 == 1,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn f64ToParts(self: f64) callconv(.C) F64Parts {
|
||||
const u64Value = @as(u64, @bitCast(self));
|
||||
return F64Parts{
|
||||
.fraction = u64Value & 0xfffffffffffff,
|
||||
.exponent = @truncate(u64Value >> 52 & 0x7ff),
|
||||
.sign = u64Value >> 63 & 1 == 1,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -151,7 +151,9 @@ interface Num
|
|||
toF64,
|
||||
toF64Checked,
|
||||
withoutDecimalPoint,
|
||||
withDecimalPoint
|
||||
withDecimalPoint,
|
||||
f32ToParts,
|
||||
f64ToParts
|
||||
]
|
||||
imports [
|
||||
Bool.{ Bool },
|
||||
|
@ -1410,8 +1412,12 @@ toF32Checked : Num * -> Result F32 [OutOfBounds]
|
|||
toF64Checked : Num * -> Result F64 [OutOfBounds]
|
||||
|
||||
|
||||
## Turns a [Dec] into its [I128] representation, effectifely removing the decimal point.
|
||||
## Turns a [Dec] into its [I128] representation by removing the decimal point.
|
||||
withoutDecimalPoint : Dec -> I128
|
||||
|
||||
## Turns a [I128] into the coresponding [Dec], effectifely addoing the decimal point.
|
||||
withDecimalPoint : I128 -> Dec
|
||||
## Turns a [I128] into the coresponding [Dec] by adding the decimal point.
|
||||
withDecimalPoint : I128 -> Dec
|
||||
|
||||
f32ToParts: F32 -> { sign : Bool, exponent : U8, fraction : U32 }
|
||||
|
||||
f64ToParts: F64 -> { sign : Bool, exponent : U16, fraction : U64 }
|
|
@ -334,6 +334,8 @@ pub const NUM_COUNT_LEADING_ZERO_BITS: IntrinsicName =
|
|||
pub const NUM_COUNT_TRAILING_ZERO_BITS: IntrinsicName =
|
||||
int_intrinsic!("roc_builtins.num.count_trailing_zero_bits");
|
||||
pub const NUM_COUNT_ONE_BITS: IntrinsicName = int_intrinsic!("roc_builtins.num.count_one_bits");
|
||||
pub const NUM_F32_TO_PARTS: &str = "roc_builtins.num.f32_to_parts";
|
||||
pub const NUM_F64_TO_PARTS: &str = "roc_builtins.num.f64_to_parts";
|
||||
|
||||
pub const STR_INIT: &str = "roc_builtins.str.init";
|
||||
pub const STR_COUNT_SEGMENTS: &str = "roc_builtins.str.count_segments";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue