Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: impl lossy_from(f64) #4

Open
OliverNChalk opened this issue Sep 13, 2024 · 1 comment
Open

feat: impl lossy_from(f64) #4

OliverNChalk opened this issue Sep 13, 2024 · 1 comment

Comments

@OliverNChalk
Copy link
Owner

Example for how to extract the mantissa & exponent:

fn raw_mantissa_and_exponent<T: PrimitiveFloat>(x: T) -> (u64, u64) {
    let bits = x.to_bits();
    let mantissa = bits.mod_power_of_2(T::MANTISSA_WIDTH);
    let exponent: u64 = (bits >> T::MANTISSA_WIDTH).exact_into();
    let exponent = exponent.mod_power_of_2(T::EXPONENT_WIDTH);
    (mantissa, exponent)
}
@OliverNChalk
Copy link
Owner Author

Actually, need to re-think if this is useful or if we should just provide a decimal! macro

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant