MCPcopy Index your code
hub / github.com/RustPython/RustPython / to_hex

Function to_hex

crates/literal/src/float.rs:233–252  ·  view source on GitHub ↗
(value: f64)

Source from the content-addressed store, hash-verified

231}
232
233pub fn to_hex(value: f64) -> String {
234 let (mantissa, exponent, sign) = value.integer_decode();
235 let sign_fmt = if sign < 0 { "-" } else { "" };
236 match value {
237 value if value.is_zero() => format!("{sign_fmt}0x0.0p+0"),
238 value if value.is_infinite() => format!("{sign_fmt}inf"),
239 value if value.is_nan() => "nan".to_owned(),
240 _ => {
241 const BITS: i16 = 52;
242 const FRACT_MASK: u64 = 0xf_ffff_ffff_ffff;
243 format!(
244 "{}{:#x}.{:013x}p{:+}",
245 sign_fmt,
246 mantissa >> BITS,
247 mantissa & FRACT_MASK,
248 exponent + BITS
249 )
250 }
251 }
252}
253
254#[test]
255fn test_to_hex() {

Callers 2

hexMethod · 0.85
test_to_hexFunction · 0.85

Calls 4

is_zeroMethod · 0.45
is_infiniteMethod · 0.45
is_nanMethod · 0.45
to_ownedMethod · 0.45

Tested by 1

test_to_hexFunction · 0.68