Add Num.[f32,f64,dec]_[to,from]_bits builtins and deprecate Num.[f32,f64]_[to,from]_parts (#7741)

* Add `Num.[f32,f64,dec]_[to,from]_bits` builtins

* Update mono tests

* Deprecate `Num.[f32,f64]_[to,from]_parts`
This commit is contained in:
Lars Frogner 2025-04-18 10:10:45 +02:00 committed by GitHub
parent 7c5bbeab4c
commit 560171c238
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
106 changed files with 821 additions and 567 deletions

View file

@ -114,6 +114,12 @@ comptime {
exportNumFn(num.f64ToParts, "f64_to_parts");
exportNumFn(num.f32FromParts, "f32_from_parts");
exportNumFn(num.f64FromParts, "f64_from_parts");
exportNumFn(num.f32ToBits, "f32_to_bits");
exportNumFn(num.f64ToBits, "f64_to_bits");
exportNumFn(num.i128ToBits, "i128_to_bits");
exportNumFn(num.f32FromBits, "f32_from_bits");
exportNumFn(num.f64FromBits, "f64_from_bits");
exportNumFn(num.i128FromBits, "i128_from_bits");
for (INTEGERS, 0..) |T, i| {
num.exportPow(T, ROC_BUILTINS ++ "." ++ NUM ++ ".pow_int.");

View file

@ -702,3 +702,27 @@ pub fn f32FromParts(parts: F32Parts) callconv(.C) f32 {
pub fn f64FromParts(parts: F64Parts) callconv(.C) f64 {
return @as(f64, @bitCast(parts.fraction & 0xfffffffffffff | (@as(u64, parts.exponent & 0x7ff) << 52) | (@as(u64, @intFromBool(parts.sign)) << 63)));
}
pub fn f32ToBits(self: f32) callconv(.C) u32 {
return @as(u32, @bitCast(self));
}
pub fn f64ToBits(self: f64) callconv(.C) u64 {
return @as(u64, @bitCast(self));
}
pub fn i128ToBits(self: i128) callconv(.C) u128 {
return @as(u128, @bitCast(self));
}
pub fn f32FromBits(bits: u32) callconv(.C) f32 {
return @as(f32, @bitCast(bits));
}
pub fn f64FromBits(bits: u64) callconv(.C) f64 {
return @as(f64, @bitCast(bits));
}
pub fn i128FromBits(bits: u128) callconv(.C) i128 {
return @as(i128, @bitCast(bits));
}