MCPcopy Create free account
hub / github.com/RustPython/RustPython / decompose_float

Function decompose_float

crates/common/src/float_ops.rs:5–14  ·  view source on GitHub ↗
(value: f64)

Source from the content-addressed store, hash-verified

3use num_traits::{Float, Signed, ToPrimitive, Zero};
4
5pub const fn decompose_float(value: f64) -> (f64, i32) {
6 if 0.0 == value {
7 (0.0, 0i32)
8 } else {
9 let bits = value.to_bits();
10 let exponent: i32 = ((bits >> 52) & 0x7ff) as i32 - 1022;
11 let mantissa_bits = bits & (0x000f_ffff_ffff_ffff) | (1022 << 52);
12 (f64::from_bits(mantissa_bits), exponent)
13 }
14}
15
16/// Equate an integer to a float.
17///

Callers 1

hash_floatFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected