mirror of
https://github.com/roc-lang/roc.git
synced 2024-10-04 22:27:55 +03:00
cut high bits for to large fraction an exponent
This commit is contained in:
parent
834015a758
commit
546cb17fb9
@ -662,9 +662,9 @@ pub fn f64ToParts(self: f64) callconv(.C) F64Parts {
|
||||
}
|
||||
|
||||
pub fn f32FromParts(parts: F32Parts) callconv(.C) f32 {
|
||||
return @as(f32, @bitCast(parts.fraction | (@as(u32, parts.exponent) << 23) | (@as(u32, @intFromBool(parts.sign)) << 31)));
|
||||
return @as(f32, @bitCast(parts.fraction & 0x7fffff | (@as(u32, parts.exponent) << 23) | (@as(u32, @intFromBool(parts.sign)) << 31)));
|
||||
}
|
||||
|
||||
pub fn f64FromParts(parts: F64Parts) callconv(.C) f64 {
|
||||
return @as(f64, @bitCast(parts.fraction | (@as(u64, parts.exponent) << 52) | (@as(u64, @intFromBool(parts.sign)) << 63)));
|
||||
return @as(f64, @bitCast(parts.fraction & 0xfffffffffffff | (@as(u64, parts.exponent & 0x7ff) << 52) | (@as(u64, @intFromBool(parts.sign)) << 63)));
|
||||
}
|
||||
|
@ -1428,7 +1428,10 @@ f32ToParts : F32 -> { sign : Bool, exponent : U8, fraction : U32 }
|
||||
f64ToParts : F64 -> { sign : Bool, exponent : U16, fraction : U64 }
|
||||
|
||||
## Combine parts of a [F32] according to IEEE 754 standard.
|
||||
## The fraction should not be bigger than 0x007F_FFFF, any bigger value will be truncated.
|
||||
f32FromParts : { sign : Bool, exponent : U8, fraction : U32 } -> F32
|
||||
|
||||
## Combine parts of a [F64] according to IEEE 754 standard.
|
||||
## The fraction should not be bigger than 0x000F_FFFF_FFFF_FFFF, any bigger value will be truncated.
|
||||
## The exponent should not be bigger than 0x07FF, any bigger value will be truncated.
|
||||
f64FromParts : { sign : Bool, exponent : U16, fraction : U64 } -> F64
|
||||
|
Loading…
Reference in New Issue
Block a user