float -> u48 conversion

This commit is contained in:
Lorenzobattistela 2024-07-19 07:57:11 -03:00
parent 8808ca6534
commit a491c3a8cc

24
book/Float/to_U48.kind2 Normal file
View File

@ -0,0 +1,24 @@
/// Constructs a U48 from a Float. It truncates the float to the next integer.
///
/// Examples:
/// - 1.25 (Float/new 125 2) -> 1 : U48
/// - 1000.0 (Float/new 1 3) -> 1000 : U48
/// - 0.75 (Float/new 75 2) -> 0 : U48
///
/// # Input
///
/// * `a` - The Float number.
///
/// # Output
///
/// The U48 representation of that number, truncated.
use Float/{new}
to_U48
- a: Float
: U48
match a {
new: (Float/to_U48/go a.mantissa a.exponent)
}