Debian Codegraph @

src/extended_float.rs

raw symbols SCIP
1 //! Extended precision floating-point type.
2 //!
3 //! Also contains helpers to convert to and from native rust floats.
4 //! This representation stores the mantissa as a 64-bit unsigned integer,
5 //! and the exponent as a 32-bit unsigned integer, allowed ~80 bits of
6 //! precision (only 16 bits of the 32-bit integer are used, u32 is used
7 //! for performance). Since there is no storage for the sign bit,
8 //! this only works for positive floats.
9
10 #![cfg(any(feature = "parse-floats", feature = "write-floats"))]
11
12 use crate::num::UnsignedInteger;
13
14 /// Extended precision floating-point type.
15 ///
16 /// This doesn't have any methods because it's used for **very** different
17 /// things for the Lemire, Bellepheron, and other algorithms. In Grisu,
18 /// it's an unbiased representation, for Lemire, it's a biased representation.
19 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
20 pub struct ExtendedFloat<M: UnsignedInteger> {
21 /// Mantissa for the extended-precision float.
22 pub mant: M,
23 /// Binary exponent for the extended-precision float.
24 pub exp: i32,
25 }
26
27 impl<M: UnsignedInteger> ExtendedFloat<M> {
28 /// Get the mantissa component.
29 #[inline(always)]
30 pub fn mantissa(&self) -> M {
31 self.mant
32 }
33
34 /// Get the exponent component.
35 #[inline(always)]
36 pub fn exponent(&self) -> i32 {
37 self.exp
38 }
39 }