/rust/registry/src/index.crates.io-1949cf8c6b5b557f/lexical-util-1.0.7/src/extended_float.rs
Line | Count | Source |
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 | 0 | pub fn mantissa(&self) -> M { |
31 | 0 | self.mant |
32 | 0 | } |
33 | | |
34 | | /// Get the exponent component. |
35 | | #[inline(always)] |
36 | 0 | pub fn exponent(&self) -> i32 { |
37 | 0 | self.exp |
38 | 0 | } |
39 | | } |