| 1 | //! Trait definitions for bitwise operations. |
| 2 | //! |
| 3 | //! Most traits are only implemented for unsigned integers yet. |
| 4 | |
| 5 | use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::numrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/::FpCategoryrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/FpCategory#; |
| 6 | |
| 7 | use craterust-analyzer cargo dashu-base 0.4.1 crate/::{ |
| 8 | Approximationrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#::{selfrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#, *}, |
| 9 | Signrust-analyzer cargo dashu-base 0.4.1 sign/Sign#::{selfrust-analyzer cargo dashu-base 0.4.1 sign/Sign#, *}, |
| 10 | }; |
| 11 | |
| 12 | /// Bit query for integers |
| 13 | /// |
| 14 | /// # Examples |
| 15 | /// |
| 16 | /// ``` |
| 17 | /// # use dashu_base::BitTest; |
| 18 | /// // query a bit of the number |
| 19 | /// assert_eq!(0b10010.bit(1), true); |
| 20 | /// assert_eq!(0b10010.bit(3), false); |
| 21 | /// assert_eq!(0b10010.bit(100), false); |
| 22 | /// assert_eq!((-0b10010).bit(1), true); |
| 23 | /// assert_eq!((-0b10010).bit(3), true); |
| 24 | /// assert_eq!((-0b10010).bit(100), true); |
| 25 | /// |
| 26 | /// // query the bit length of the number |
| 27 | /// assert_eq!(0.bit_len(), 0); |
| 28 | /// assert_eq!(17.bit_len(), 5); |
| 29 | /// assert_eq!((-17).bit_len(), 5); |
| 30 | /// assert_eq!(0b101000000.bit_len(), 9); |
| 31 | /// ``` |
| 32 | pub trait BitTestrust-analyzer cargo dashu-base 0.4.1 bit/BitTest# { |
| 33 | /// Effective bit length of the binary representation. |
| 34 | /// |
| 35 | /// For 0, the length is 0. |
| 36 | /// |
| 37 | /// For positive numbers it is: |
| 38 | /// * number of digits in base 2 |
| 39 | /// * the index of the top 1 bit plus one |
| 40 | /// * the floored base-2 logarithm of the number plus one. |
| 41 | /// |
| 42 | /// For negative numbers it is: |
| 43 | /// * number of digits in base 2 without the sign |
| 44 | /// * the index of the top 0 bit plus one |
| 45 | /// * the floored base-2 logarithm of the absolute value of the number plus one. |
| 46 | fn bit_lenrust-analyzer cargo dashu-base 0.4.1 bit/BitTest#bit_len().(&self) -> usize; |
| 47 | |
| 48 | /// Returns true if the `n`-th bit is set in its two's complement binary representation, n starts from 0. |
| 49 | fn bitrust-analyzer cargo dashu-base 0.4.1 bit/BitTest#bit().(&self, n: usize) -> bool; |
| 50 | } |
| 51 | |
| 52 | /// Functions related to the power of two. |
| 53 | /// |
| 54 | /// # Examples |
| 55 | /// ``` |
| 56 | /// use dashu_base::PowerOfTwo; |
| 57 | /// |
| 58 | /// let n = 5u32; |
| 59 | /// assert!(!n.is_power_of_two()); |
| 60 | /// assert_eq!(n.next_power_of_two(), 8); |
| 61 | /// ``` |
| 62 | pub trait PowerOfTworust-analyzer cargo dashu-base 0.4.1 bit/PowerOfTwo# { |
| 63 | /// Test if self is a power of two (`2^k`) |
| 64 | fn is_power_of_tworust-analyzer cargo dashu-base 0.4.1 bit/PowerOfTwo#is_power_of_two().(&self) -> bool; |
| 65 | /// Get the smallest power of two greater than or equal to self. |
| 66 | fn next_power_of_tworust-analyzer cargo dashu-base 0.4.1 bit/PowerOfTwo#next_power_of_two().(self) -> Self; |
| 67 | } |
| 68 | |
| 69 | macro_rules! impl_bit_ops_for_uintrust-analyzer cargo dashu-base 0.4.1 bit/impl_bit_ops_for_uint! { |
| 70 | ($($T:ty)*) => {$( |
| 71 | impl BitTest for $T { |
| 72 | #[inline] |
| 73 | fn bit_len(&self) -> usize { |
| 74 | (<$T>::BITS - self.leading_zeros()) as usize |
| 75 | } |
| 76 | #[inline] |
| 77 | fn bit(&self, position: usize) -> bool { |
| 78 | if position >= <$T>::BITS as usize { |
| 79 | return false; |
| 80 | } else { |
| 81 | self & (1 << position) > 0 |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | impl PowerOfTwo for $T { |
| 87 | #[inline] |
| 88 | fn is_power_of_two(&self) -> bool { |
| 89 | <$T>::is_power_of_two(*self) |
| 90 | } |
| 91 | #[inline] |
| 92 | fn next_power_of_two(self) -> $T { |
| 93 | <$T>::next_power_of_two(self) |
| 94 | } |
| 95 | } |
| 96 | )*} |
| 97 | } |
| 98 | impl_bit_ops_for_uintrust-analyzer cargo dashu-base 0.4.1 bit/impl_bit_ops_for_uint!!(u8 u16 u32 u64 u128 usize); |
| 99 | |
| 100 | macro_rules! impl_bit_ops_for_intrust-analyzer cargo dashu-base 0.4.1 bit/impl_bit_ops_for_int! { |
| 101 | ($($T:ty)*) => {$( |
| 102 | impl BitTest for $T { |
| 103 | #[inline] |
| 104 | fn bit_len(&self) -> usize { |
| 105 | self.unsigned_abs().bit_len() |
| 106 | } |
| 107 | #[inline] |
| 108 | fn bit(&self, position: usize) -> bool { |
| 109 | if position >= <$T>::BITS as usize { |
| 110 | return self < &0; |
| 111 | } else { |
| 112 | self & (1 << position) > 0 |
| 113 | } |
| 114 | } |
| 115 | } |
| 116 | )*} |
| 117 | } |
| 118 | impl_bit_ops_for_intrust-analyzer cargo dashu-base 0.4.1 bit/impl_bit_ops_for_int!!(i8 i16 i32 i64 i128 isize); |
| 119 | |
| 120 | /// Support encoding and decoding of floats into (mantissa, exponent) parts. |
| 121 | /// |
| 122 | /// See the docs of each method for the details |
| 123 | /// |
| 124 | /// # Examples |
| 125 | /// |
| 126 | /// ``` |
| 127 | /// # use dashu_base::{FloatEncoding, Approximation::*, Sign::*}; |
| 128 | /// use core::num::FpCategory; |
| 129 | /// |
| 130 | /// assert_eq!(0f64.decode(), Ok((0, -1074))); // exponent will not be reduced |
| 131 | /// assert_eq!(1f32.decode(), Ok((1 << 23, -23))); |
| 132 | /// assert_eq!(f32::INFINITY.decode(), Err(FpCategory::Infinite)); |
| 133 | /// |
| 134 | /// assert_eq!(f64::encode(0, 1), Exact(0f64)); |
| 135 | /// assert_eq!(f32::encode(1, 0), Exact(1f32)); |
| 136 | /// assert_eq!(f32::encode(i32::MAX, 100), Inexact(f32::INFINITY, Positive)); |
| 137 | /// ``` |
| 138 | pub trait FloatEncodingrust-analyzer cargo dashu-base 0.4.1 bit/FloatEncoding# { |
| 139 | type Mantissarust-analyzer cargo dashu-base 0.4.1 bit/FloatEncoding#Mantissa#; |
| 140 | type Exponentrust-analyzer cargo dashu-base 0.4.1 bit/FloatEncoding#Exponent#; |
| 141 | |
| 142 | /// Convert a float number `mantissa * 2^exponent` into `(mantissa, exponent)` parts faithfully. |
| 143 | /// |
| 144 | /// This method will not reduce the result (e.g. turn `2 * 2^-1` into `1 * 2^0`), and it |
| 145 | /// will return [Err] when the float number is nan or infinite. |
| 146 | fn decoderust-analyzer cargo dashu-base 0.4.1 bit/FloatEncoding#decode().(self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(Self::Mantissarust-analyzer cargo dashu-base 0.4.1 bit/FloatEncoding#Mantissa#, Self::Exponentrust-analyzer cargo dashu-base 0.4.1 bit/FloatEncoding#Exponent#), FpCategoryrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/FpCategory#>; |
| 147 | |
| 148 | /// Convert `(mantissa, exponent)` to `mantissa * 2^exponent` faithfully. |
| 149 | /// |
| 150 | /// It won't generate `NaN` values. However if the actual value is out of the |
| 151 | /// representation range, it might return an infinity or subnormal number. |
| 152 | /// |
| 153 | /// If any rounding happened during the conversion, it should follow the default |
| 154 | /// behavior defined by IEEE 754 (round to nearest, ties to even) |
| 155 | /// |
| 156 | /// The returned approximation is exact if the input can be exactly representable by f32, |
| 157 | /// otherwise the error field of the approximation contains the sign of `result - mantissa * 2^exp`. |
| 158 | fn encoderust-analyzer cargo dashu-base 0.4.1 bit/FloatEncoding#encode().(mantissa: Self::Mantissarust-analyzer cargo dashu-base 0.4.1 bit/FloatEncoding#Mantissa#, exponent: Self::Exponentrust-analyzer cargo dashu-base 0.4.1 bit/FloatEncoding#Exponent#) -> Approximationrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#<Self, Signrust-analyzer cargo dashu-base 0.4.1 sign/Sign#> |
| 159 | where |
| 160 | Self: Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#; |
| 161 | } |
| 162 | |
| 163 | /// Round to even floating point adjustment, based on the bottom |
| 164 | /// bit of mantissa and additional 2 bits (i.e. 3 bits in units of ULP/4). |
| 165 | #[inline] |
| 166 | fn round_to_even_adjustmentrust-analyzer cargo dashu-base 0.4.1 bit/round_to_even_adjustment().(bits: u8) -> bool { |
| 167 | bits rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]ge().0b110 || bits rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().0b011 |
| 168 | } |
| 169 | |
| 170 | impl FloatEncodingrust-analyzer cargo dashu-base 0.4.1 bit/FloatEncoding# for f32 { |
| 171 | type Mantissarust-analyzer cargo dashu-base 0.4.1 bit/impl#[f32][FloatEncoding]Mantissa# = i32; |
| 172 | type Exponentrust-analyzer cargo dashu-base 0.4.1 bit/impl#[f32][FloatEncoding]Exponent# = i16; |
| 173 | |
| 174 | #[inline] |
| 175 | fn decoderust-analyzer cargo dashu-base 0.4.1 bit/impl#[f32][FloatEncoding]decode().(self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(i32, i16), FpCategoryrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/FpCategory#> { |
| 176 | let bits: u32 = self.to_bitsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f32/impl#[f32]to_bits().(); |
| 177 | let sign_bit = bits rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr().>>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr().31; |
| 178 | let mantissa_bits = bits rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand().0x7fffff; |
| 179 | |
| 180 | // deal with inf/nan values |
| 181 | let mut exponent = ((bits rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr().>>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr().23) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand().0xff) as i16; |
| 182 | if exponent rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialEq<Self>`]eq().0xff { |
| 183 | return if mantissa_bits rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]ne().0 { |
| 184 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(FpCategoryrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/FpCategory#::Nanrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/FpCategory#Nan#) |
| 185 | } else { |
| 186 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(FpCategoryrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/FpCategory#::Infiniterust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/FpCategory#Infinite#) |
| 187 | }; |
| 188 | } |
| 189 | |
| 190 | // then parse values |
| 191 | let mantissa = if exponent rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialEq<Self>`]eq().0 { |
| 192 | // subnormal |
| 193 | exponent = -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][Neg]neg().126 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Sub<Self>`]sub().23; |
| 194 | mantissa_bits |
| 195 | } else { |
| 196 | // normal |
| 197 | exponent rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`SubAssign<Self>`]sub_assign().127 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add().23; // bias + mantissa shift |
| 198 | mantissa_bits rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().0x800000 |
| 199 | } as i32; |
| 200 | |
| 201 | let sign = Signrust-analyzer cargo dashu-base 0.4.1 sign/Sign#::fromrust-analyzer cargo dashu-base 0.4.1 sign/impl#[Sign][`From<bool>`]from().(sign_bit rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]gt().0); |
| 202 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#((mantissa rust-analyzer cargo dashu-base 0.4.1 sign/impl#[i32][`Mul<Sign>`]mul().*rust-analyzer cargo dashu-base 0.4.1 sign/impl#[i32][`Mul<Sign>`]mul(). rust-analyzer cargo dashu-base 0.4.1 sign/impl#[i32][`Mul<Sign>`]mul().sign, exponent)) |
| 203 | } |
| 204 | |
| 205 | #[inline] |
| 206 | fn encoderust-analyzer cargo dashu-base 0.4.1 bit/impl#[f32][FloatEncoding]encode().(mantissa: i32, exponent: i16) -> Approximationrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#<Selfrust-analyzer cargo dashu-base 0.4.1 bit/impl#[f32][FloatEncoding], Signrust-analyzer cargo dashu-base 0.4.1 sign/Sign#> { |
| 207 | if mantissa rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().0 { |
| 208 | return Exactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Exact#(0f32); |
| 209 | } |
| 210 | |
| 211 | // clear sign |
| 212 | let sign = (mantissa rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]lt().0) as u32; |
| 213 | let mut mantissa = mantissa.unsigned_absrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i32]unsigned_abs().(); |
| 214 | |
| 215 | let zeros = mantissa.leading_zerosrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u32]leading_zeros().(); |
| 216 | let top_bit = (u32::BITSrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u32]BITS. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub().zeros) as i16 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add().exponent; |
| 217 | |
| 218 | if top_bit rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]gt().128 { |
| 219 | // overflow |
| 220 | return if sign rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().0 { |
| 221 | Inexactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Inexact#(f32::INFINITYrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f32/impl#[f32]INFINITY., Signrust-analyzer cargo dashu-base 0.4.1 sign/Sign#::Positiverust-analyzer cargo dashu-base 0.4.1 sign/Sign#Positive#) |
| 222 | } else { |
| 223 | Inexactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Inexact#(f32::NEG_INFINITYrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f32/impl#[f32]NEG_INFINITY., Signrust-analyzer cargo dashu-base 0.4.1 sign/Sign#::Negativerust-analyzer cargo dashu-base 0.4.1 sign/Sign#Negative#) |
| 224 | }; |
| 225 | } else if top_bit rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]lt().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][Neg]neg().125 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Sub<Self>`]sub().23 { |
| 226 | // underflow |
| 227 | return if sign rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().0 { |
| 228 | Inexactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Inexact#(0f32, Signrust-analyzer cargo dashu-base 0.4.1 sign/Sign#::Negativerust-analyzer cargo dashu-base 0.4.1 sign/Sign#Negative#) |
| 229 | } else { |
| 230 | Inexactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Inexact#(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][Neg]neg().0f32, Signrust-analyzer cargo dashu-base 0.4.1 sign/Sign#::Positiverust-analyzer cargo dashu-base 0.4.1 sign/Sign#Positive#) |
| 231 | }; |
| 232 | }; |
| 233 | |
| 234 | let bits; // bit representation |
| 235 | let round_bits; // for rounding |
| 236 | if top_bit rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]le().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][Neg]neg().125 { |
| 237 | // subnormal float |
| 238 | // (this branch includes 1e-125, the smallest positive normal f32) |
| 239 | |
| 240 | // first remove the exponent |
| 241 | let shift = exponent rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add().126 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add().23; |
| 242 | if shift rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]ge().0 { |
| 243 | round_bits = 0; // not rounding is required |
| 244 | mantissa rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`ShlAssign<Self>`]shl_assign().<<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`ShlAssign<Self>`]shl_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`ShlAssign<Self>`]shl_assign().shift as u32; |
| 245 | } else { |
| 246 | let shifted = mantissa rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<Self>`]shl().<<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<Self>`]shl(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<Self>`]shl().(30 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add().shift) as u32; |
| 247 | round_bits = (shifted rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr().>>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr().28 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand().0b110) as u8 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().((shifted rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand().0xfffffff) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]ne().0) as u8; |
| 248 | mantissa rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`ShrAssign<Self>`]shr_assign().>>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`ShrAssign<Self>`]shr_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`ShrAssign<Self>`]shr_assign().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][Neg]neg().shift) as u32; |
| 249 | } |
| 250 | |
| 251 | // then compose the bit representation of f32 |
| 252 | bits = (sign rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl().<<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl().31) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().mantissa; |
| 253 | } else { |
| 254 | // normal float |
| 255 | // first normalize the mantissa (and remove the top bit) |
| 256 | if mantissa rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().1 { |
| 257 | mantissa = 0; // shl will overflow |
| 258 | } else { |
| 259 | mantissa rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`ShlAssign<Self>`]shl_assign().<<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`ShlAssign<Self>`]shl_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`ShlAssign<Self>`]shl_assign().zeros rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().1; |
| 260 | } |
| 261 | |
| 262 | // then calculate the exponent (bias is 127) |
| 263 | let exponent = (exponent rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add().127 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add().u32::BITSrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u32]BITS. as i16) as u32 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub().zeros rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub().1; |
| 264 | |
| 265 | // then compose the bit representation of f32 |
| 266 | bits = (sign rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl().<<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl().31) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().(exponent rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl().<<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shl<i32>`]shl().23) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitOr<Self>`]bitor().(mantissa rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr().>>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr().9); |
| 267 | |
| 268 | // get the low bit of mantissa and two extra bits, and adding round-to-even adjustment |
| 269 | round_bits = ((mantissa rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr().>>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr().7) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand().0b110) as u8 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().((mantissa rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand().0x7f) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]ne().0) as u8; |
| 270 | }; |
| 271 | |
| 272 | if round_bits rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand().0b11 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().0 { |
| 273 | // If two extra bits are all zeros, then the float is exact |
| 274 | Exactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Exact#(f32::from_bitsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f32/impl#[f32]from_bits().(bits)) |
| 275 | } else { |
| 276 | let sign = Signrust-analyzer cargo dashu-base 0.4.1 sign/Sign#::fromrust-analyzer cargo dashu-base 0.4.1 sign/impl#[Sign][`From<bool>`]from().(sign rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]gt().0); |
| 277 | if round_to_even_adjustmentrust-analyzer cargo dashu-base 0.4.1 bit/round_to_even_adjustment().(round_bits) { |
| 278 | // If the mantissa overflows, this correctly increases the exponent and sets the mantissa to 0. |
| 279 | // If the exponent overflows, we correctly get the representation of infinity. |
| 280 | Inexactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Inexact#(f32::from_bitsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f32/impl#[f32]from_bits().(bits rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().1), Positiverust-analyzer cargo dashu-base 0.4.1 sign/Sign#Positive# rust-analyzer cargo dashu-base 0.4.1 sign/impl#[Sign][`Mul<Self>`]mul().*rust-analyzer cargo dashu-base 0.4.1 sign/impl#[Sign][`Mul<Self>`]mul(). rust-analyzer cargo dashu-base 0.4.1 sign/impl#[Sign][`Mul<Self>`]mul().sign) |
| 281 | } else { |
| 282 | Inexactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Inexact#(f32::from_bitsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f32/impl#[f32]from_bits().(bits), Negativerust-analyzer cargo dashu-base 0.4.1 sign/Sign#Negative# rust-analyzer cargo dashu-base 0.4.1 sign/impl#[Sign][`Mul<Self>`]mul().*rust-analyzer cargo dashu-base 0.4.1 sign/impl#[Sign][`Mul<Self>`]mul(). rust-analyzer cargo dashu-base 0.4.1 sign/impl#[Sign][`Mul<Self>`]mul().sign) |
| 283 | } |
| 284 | } |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | impl FloatEncodingrust-analyzer cargo dashu-base 0.4.1 bit/FloatEncoding# for f64 { |
| 289 | type Mantissarust-analyzer cargo dashu-base 0.4.1 bit/impl#[f64][FloatEncoding]Mantissa# = i64; |
| 290 | type Exponentrust-analyzer cargo dashu-base 0.4.1 bit/impl#[f64][FloatEncoding]Exponent# = i16; |
| 291 | |
| 292 | #[inline] |
| 293 | fn decoderust-analyzer cargo dashu-base 0.4.1 bit/impl#[f64][FloatEncoding]decode().(self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(i64, i16), FpCategoryrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/FpCategory#> { |
| 294 | let bits: u64 = self.to_bitsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f64/impl#[f64]to_bits().(); |
| 295 | let sign_bit = bits rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`Shr<i32>`]shr().>>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`Shr<i32>`]shr(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`Shr<i32>`]shr().63; |
| 296 | let mantissa_bits = bits rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitAnd<Self>`]bitand().0xfffffffffffff; |
| 297 | |
| 298 | // deal with inf/nan values |
| 299 | let mut exponent = ((bits rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`Shr<i32>`]shr().>>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`Shr<i32>`]shr(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`Shr<i32>`]shr().52) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitAnd<Self>`]bitand().0x7ff) as i16; |
| 300 | if exponent rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialEq<Self>`]eq().0x7ff { |
| 301 | return if mantissa_bits rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]ne().0 { |
| 302 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(FpCategoryrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/FpCategory#::Nanrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/FpCategory#Nan#) |
| 303 | } else { |
| 304 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(FpCategoryrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/FpCategory#::Infiniterust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/FpCategory#Infinite#) |
| 305 | }; |
| 306 | } |
| 307 | |
| 308 | // then parse values |
| 309 | let mantissa = if exponent rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialEq<Self>`]eq().0 { |
| 310 | // subnormal |
| 311 | exponent = -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][Neg]neg().1022 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Sub<Self>`]sub().52; |
| 312 | mantissa_bits |
| 313 | } else { |
| 314 | // normal |
| 315 | exponent rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`SubAssign<Self>`]sub_assign().1023 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add().52; // bias + mantissa shift |
| 316 | mantissa_bits rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitOr<Self>`]bitor().0x10000000000000 |
| 317 | } as i64; |
| 318 | |
| 319 | if sign_bit rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]eq().0 { |
| 320 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#((mantissa, exponent)) |
| 321 | } else { |
| 322 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#((-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][Neg]neg().mantissa, exponent)) |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | #[inline] |
| 327 | fn encoderust-analyzer cargo dashu-base 0.4.1 bit/impl#[f64][FloatEncoding]encode().(mantissa: i64, exponent: i16) -> Approximationrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#<Selfrust-analyzer cargo dashu-base 0.4.1 bit/impl#[f64][FloatEncoding], Signrust-analyzer cargo dashu-base 0.4.1 sign/Sign#> { |
| 328 | if mantissa rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialEq<Self>`]eq().0 { |
| 329 | return Exactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Exact#(0f64); |
| 330 | } |
| 331 | |
| 332 | // clear sign |
| 333 | let sign = (mantissa rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialOrd<Self>`]lt().0) as u64; |
| 334 | let mut mantissa = mantissa.unsigned_absrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i64]unsigned_abs().(); |
| 335 | |
| 336 | let zeros = mantissa.leading_zerosrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]leading_zeros().(); |
| 337 | let top_bit = (u64::BITSrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]BITS. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub().zeros) as i16 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add().exponent; |
| 338 | |
| 339 | if top_bit rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]gt().1024 { |
| 340 | // overflow |
| 341 | return if sign rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]eq().0 { |
| 342 | Inexactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Inexact#(f64::INFINITYrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f64/impl#[f64]INFINITY., Signrust-analyzer cargo dashu-base 0.4.1 sign/Sign#::Positiverust-analyzer cargo dashu-base 0.4.1 sign/Sign#Positive#) |
| 343 | } else { |
| 344 | Inexactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Inexact#(f64::NEG_INFINITYrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f64/impl#[f64]NEG_INFINITY., Signrust-analyzer cargo dashu-base 0.4.1 sign/Sign#::Negativerust-analyzer cargo dashu-base 0.4.1 sign/Sign#Negative#) |
| 345 | }; |
| 346 | } else if top_bit rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]lt().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][Neg]neg().1022 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Sub<Self>`]sub().52 { |
| 347 | // underflow |
| 348 | return if sign rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]eq().0 { |
| 349 | Inexactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Inexact#(0f64, Signrust-analyzer cargo dashu-base 0.4.1 sign/Sign#::Negativerust-analyzer cargo dashu-base 0.4.1 sign/Sign#Negative#) |
| 350 | } else { |
| 351 | Inexactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Inexact#(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().0f64, Signrust-analyzer cargo dashu-base 0.4.1 sign/Sign#::Positiverust-analyzer cargo dashu-base 0.4.1 sign/Sign#Positive#) |
| 352 | }; |
| 353 | }; |
| 354 | |
| 355 | let bits; // bit representation |
| 356 | let round_bits; // for rounding |
| 357 | if top_bit rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]le().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][Neg]neg().1022 { |
| 358 | // subnormal float |
| 359 | // (this branch includes 1e-1022, the smallest positive normal f32) |
| 360 | |
| 361 | // first remove the exponent |
| 362 | let shift = exponent rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add().1022 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add().52; |
| 363 | if shift rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]ge().0 { |
| 364 | round_bits = 0; // not rounding is required |
| 365 | mantissa rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`ShlAssign<u32>`]shl_assign().<<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`ShlAssign<u32>`]shl_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`ShlAssign<u32>`]shl_assign().shift as u32; |
| 366 | } else { |
| 367 | let shifted = mantissa rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`Shl<Self>`]shl().<<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`Shl<Self>`]shl(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`Shl<Self>`]shl().(62 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add().shift) as u64; |
| 368 | round_bits = |
| 369 | (shifted rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`Shr<i32>`]shr().>>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`Shr<i32>`]shr(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`Shr<i32>`]shr().60 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitAnd<Self>`]bitand().0b110) as u8 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().((shifted rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitAnd<Self>`]bitand().0xfffffffffffffff) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]ne().0) as u8; |
| 370 | mantissa rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`ShrAssign<u32>`]shr_assign().>>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`ShrAssign<u32>`]shr_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`ShrAssign<u32>`]shr_assign().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][Neg]neg().shift) as u32; |
| 371 | } |
| 372 | |
| 373 | // then compose the bit representation of f64 |
| 374 | bits = (sign rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`Shl<i32>`]shl().<<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`Shl<i32>`]shl(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`Shl<i32>`]shl().63) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitOr<Self>`]bitor().mantissa; |
| 375 | } else { |
| 376 | // normal float |
| 377 | // first normalize the mantissa (and remove the top bit) |
| 378 | if mantissa rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]eq().1 { |
| 379 | mantissa = 0; // shl will overflow |
| 380 | } else { |
| 381 | mantissa rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`ShlAssign<u32>`]shl_assign().<<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`ShlAssign<u32>`]shl_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`ShlAssign<u32>`]shl_assign().zeros rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().1; |
| 382 | } |
| 383 | |
| 384 | // then calculate the exponent (bias is 1023) |
| 385 | let exponent = (exponent rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add().1023 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add().u64::BITSrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]BITS. as i16) as u64 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Sub<Self>`]sub().zeros as u64 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Sub<Self>`]sub().1; |
| 386 | |
| 387 | // then compose the bit representation of f64 |
| 388 | bits = (sign rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`Shl<i32>`]shl().<<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`Shl<i32>`]shl(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`Shl<i32>`]shl().63) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitOr<Self>`]bitor().(exponent rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`Shl<i32>`]shl().<<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`Shl<i32>`]shl(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`Shl<i32>`]shl().52) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitOr<Self>`]bitor().(mantissa rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`Shr<i32>`]shr().>>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`Shr<i32>`]shr(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`Shr<i32>`]shr().12); |
| 389 | |
| 390 | // get the low bit of mantissa and two extra bits, and adding round-to-even adjustment |
| 391 | round_bits = ((mantissa rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`Shr<i32>`]shr().>>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`Shr<i32>`]shr(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`Shr<i32>`]shr().10) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitAnd<Self>`]bitand().0b110) as u8 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitOr<Self>`]bitor().((mantissa rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitAnd<Self>`]bitand().0x3ff) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]ne().0) as u8; |
| 392 | }; |
| 393 | |
| 394 | if round_bits rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u8][`BitAnd<Self>`]bitand().0b11 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().0 { |
| 395 | // If two extra bits are all zeros, then the float is exact |
| 396 | Exactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Exact#(f64::from_bitsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f64/impl#[f64]from_bits().(bits)) |
| 397 | } else { |
| 398 | let sign = Signrust-analyzer cargo dashu-base 0.4.1 sign/Sign#::fromrust-analyzer cargo dashu-base 0.4.1 sign/impl#[Sign][`From<bool>`]from().(sign rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]gt().0); |
| 399 | if round_to_even_adjustmentrust-analyzer cargo dashu-base 0.4.1 bit/round_to_even_adjustment().(round_bits) { |
| 400 | // If the mantissa overflows, this correctly increases the exponent and sets the mantissa to 0. |
| 401 | // If the exponent overflows, we correctly get the representation of infinity. |
| 402 | Inexactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Inexact#(f64::from_bitsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f64/impl#[f64]from_bits().(bits rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Add<Self>`]add().1), Positiverust-analyzer cargo dashu-base 0.4.1 sign/Sign#Positive# rust-analyzer cargo dashu-base 0.4.1 sign/impl#[Sign][`Mul<Self>`]mul().*rust-analyzer cargo dashu-base 0.4.1 sign/impl#[Sign][`Mul<Self>`]mul(). rust-analyzer cargo dashu-base 0.4.1 sign/impl#[Sign][`Mul<Self>`]mul().sign) |
| 403 | } else { |
| 404 | Inexactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Inexact#(f64::from_bitsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f64/impl#[f64]from_bits().(bits), Negativerust-analyzer cargo dashu-base 0.4.1 sign/Sign#Negative# rust-analyzer cargo dashu-base 0.4.1 sign/impl#[Sign][`Mul<Self>`]mul().*rust-analyzer cargo dashu-base 0.4.1 sign/impl#[Sign][`Mul<Self>`]mul(). rust-analyzer cargo dashu-base 0.4.1 sign/impl#[Sign][`Mul<Self>`]mul().sign) |
| 405 | } |
| 406 | } |
| 407 | } |
| 408 | } |
| 409 | |
| 410 | #[cfg(test)] |
| 411 | mod testsrust-analyzer cargo dashu-base 0.4.1 bit/tests/ { |
| 412 | use superrust-analyzer cargo dashu-base 0.4.1 bit/::*; |
| 413 | |
| 414 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 415 | fn test_float_encodingrust-analyzer cargo dashu-base 0.4.1 bit/tests/test_float_encoding().() { |
| 416 | // special values |
| 417 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(f32::INFINITYrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f32/impl#[f32]INFINITY..decoderust-analyzer cargo dashu-base 0.4.1 bit/impl#[f32][FloatEncoding]decode().(), Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(FpCategoryrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/FpCategory#::Infiniterust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/FpCategory#Infinite#)); |
| 418 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(f32::NEG_INFINITYrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f32/impl#[f32]NEG_INFINITY..decoderust-analyzer cargo dashu-base 0.4.1 bit/impl#[f32][FloatEncoding]decode().(), Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(FpCategoryrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/FpCategory#::Infiniterust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/FpCategory#Infinite#)); |
| 419 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(f32::NANrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f32/impl#[f32]NAN..decoderust-analyzer cargo dashu-base 0.4.1 bit/impl#[f32][FloatEncoding]decode().(), Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(FpCategoryrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/FpCategory#::Nanrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/FpCategory#Nan#)); |
| 420 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(f64::INFINITYrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f64/impl#[f64]INFINITY..decoderust-analyzer cargo dashu-base 0.4.1 bit/impl#[f64][FloatEncoding]decode().(), Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(FpCategoryrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/FpCategory#::Infiniterust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/FpCategory#Infinite#)); |
| 421 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(f64::NEG_INFINITYrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f64/impl#[f64]NEG_INFINITY..decoderust-analyzer cargo dashu-base 0.4.1 bit/impl#[f64][FloatEncoding]decode().(), Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(FpCategoryrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/FpCategory#::Infiniterust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/FpCategory#Infinite#)); |
| 422 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(f64::NANrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f64/impl#[f64]NAN..decoderust-analyzer cargo dashu-base 0.4.1 bit/impl#[f64][FloatEncoding]decode().(), Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(FpCategoryrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/FpCategory#::Nanrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/FpCategory#Nan#)); |
| 423 | |
| 424 | // round trip test |
| 425 | let f32_cases = [ |
| 426 | 0., |
| 427 | -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][Neg]neg().1., |
| 428 | 1., |
| 429 | f32::MINrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f32/impl#[f32]MIN., |
| 430 | f32::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f32/impl#[f32]MAX., |
| 431 | f32::MIN_POSITIVErust-analyzer cargo core https://github.com/rust-lang/rust/library/core f32/impl#[f32]MIN_POSITIVE., |
| 432 | -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][Neg]neg().f32::MIN_POSITIVErust-analyzer cargo core https://github.com/rust-lang/rust/library/core f32/impl#[f32]MIN_POSITIVE., |
| 433 | f32::EPSILONrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f32/impl#[f32]EPSILON., |
| 434 | f32::from_bitsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f32/impl#[f32]from_bits().(0x1), // smallest f32 |
| 435 | f32::from_bitsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f32/impl#[f32]from_bits().(0x7ff), // some subnormal value |
| 436 | f32::from_bitsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f32/impl#[f32]from_bits().(0x7fffff), // largest subnormal number |
| 437 | f32::from_bitsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f32/impl#[f32]from_bits().(0x800000), // smallest normal number |
| 438 | -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][Neg]neg().123.4567, |
| 439 | corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::f32rust-analyzer cargo core https://github.com/rust-lang/rust/library/core f32/::constsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f32/consts/::PIrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f32/consts/PI., |
| 440 | ]; |
| 441 | for f in f32_cases { |
| 442 | let (man, exp) = f.decoderust-analyzer cargo dashu-base 0.4.1 bit/impl#[f32][FloatEncoding]decode().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 443 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(f32::encoderust-analyzer cargo dashu-base 0.4.1 bit/impl#[f32][FloatEncoding]encode().(man, exp), Exactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Exact#(f)); |
| 444 | } |
| 445 | |
| 446 | let f64_cases = [ |
| 447 | 0., |
| 448 | -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().1., |
| 449 | 1., |
| 450 | f64::MINrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f64/impl#[f64]MIN., |
| 451 | f64::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f64/impl#[f64]MAX., |
| 452 | f64::MIN_POSITIVErust-analyzer cargo core https://github.com/rust-lang/rust/library/core f64/impl#[f64]MIN_POSITIVE., |
| 453 | -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().f64::MIN_POSITIVErust-analyzer cargo core https://github.com/rust-lang/rust/library/core f64/impl#[f64]MIN_POSITIVE., |
| 454 | f64::EPSILONrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f64/impl#[f64]EPSILON., |
| 455 | f64::from_bitsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f64/impl#[f64]from_bits().(0x1), // smallest f64 |
| 456 | f64::from_bitsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f64/impl#[f64]from_bits().(0x7fffff), // largest subnormal number |
| 457 | f64::from_bitsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f64/impl#[f64]from_bits().(0xfffffffffffff), // some subnormal value |
| 458 | f64::from_bitsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f64/impl#[f64]from_bits().(0x10000000000000), // smallest normal number |
| 459 | -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().123456.789012345, |
| 460 | corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::f64rust-analyzer cargo core https://github.com/rust-lang/rust/library/core f64/::constsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f64/consts/::PIrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f64/consts/PI., |
| 461 | ]; |
| 462 | for f in f64_cases { |
| 463 | let (man, exp) = f.decoderust-analyzer cargo dashu-base 0.4.1 bit/impl#[f64][FloatEncoding]decode().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 464 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(f64::encoderust-analyzer cargo dashu-base 0.4.1 bit/impl#[f64][FloatEncoding]encode().(man, exp), Exactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Exact#(f)); |
| 465 | } |
| 466 | |
| 467 | // test out of ranges |
| 468 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(f32::encoderust-analyzer cargo dashu-base 0.4.1 bit/impl#[f32][FloatEncoding]encode().(1, 128), Inexactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Inexact#(f32::INFINITYrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f32/impl#[f32]INFINITY., Signrust-analyzer cargo dashu-base 0.4.1 sign/Sign#::Positiverust-analyzer cargo dashu-base 0.4.1 sign/Sign#Positive#)); |
| 469 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(f32::encoderust-analyzer cargo dashu-base 0.4.1 bit/impl#[f32][FloatEncoding]encode().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().1, 128), Inexactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Inexact#(f32::NEG_INFINITYrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f32/impl#[f32]NEG_INFINITY., Signrust-analyzer cargo dashu-base 0.4.1 sign/Sign#::Negativerust-analyzer cargo dashu-base 0.4.1 sign/Sign#Negative#)); |
| 470 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(f32::encoderust-analyzer cargo dashu-base 0.4.1 bit/impl#[f32][FloatEncoding]encode().(1, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][Neg]neg().150), Inexactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Inexact#(0f32, Signrust-analyzer cargo dashu-base 0.4.1 sign/Sign#::Negativerust-analyzer cargo dashu-base 0.4.1 sign/Sign#Negative#)); |
| 471 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(f32::encoderust-analyzer cargo dashu-base 0.4.1 bit/impl#[f32][FloatEncoding]encode().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().1, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][Neg]neg().150), Inexactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Inexact#(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][Neg]neg().0f32, Signrust-analyzer cargo dashu-base 0.4.1 sign/Sign#::Positiverust-analyzer cargo dashu-base 0.4.1 sign/Sign#Positive#)); |
| 472 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(f64::encoderust-analyzer cargo dashu-base 0.4.1 bit/impl#[f64][FloatEncoding]encode().(1, 1024), Inexactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Inexact#(f64::INFINITYrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f64/impl#[f64]INFINITY., Signrust-analyzer cargo dashu-base 0.4.1 sign/Sign#::Positiverust-analyzer cargo dashu-base 0.4.1 sign/Sign#Positive#)); |
| 473 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(f64::encoderust-analyzer cargo dashu-base 0.4.1 bit/impl#[f64][FloatEncoding]encode().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][Neg]neg().1, 1024), Inexactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Inexact#(f64::NEG_INFINITYrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f64/impl#[f64]NEG_INFINITY., Signrust-analyzer cargo dashu-base 0.4.1 sign/Sign#::Negativerust-analyzer cargo dashu-base 0.4.1 sign/Sign#Negative#)); |
| 474 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(f64::encoderust-analyzer cargo dashu-base 0.4.1 bit/impl#[f64][FloatEncoding]encode().(1, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][Neg]neg().1075), Inexactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Inexact#(0f64, Signrust-analyzer cargo dashu-base 0.4.1 sign/Sign#::Negativerust-analyzer cargo dashu-base 0.4.1 sign/Sign#Negative#)); |
| 475 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(f64::encoderust-analyzer cargo dashu-base 0.4.1 bit/impl#[f64][FloatEncoding]encode().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][Neg]neg().1, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][Neg]neg().1075), Inexactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Inexact#(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().0f64, Signrust-analyzer cargo dashu-base 0.4.1 sign/Sign#::Positiverust-analyzer cargo dashu-base 0.4.1 sign/Sign#Positive#)); |
| 476 | |
| 477 | // test rounding |
| 478 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(f32::encoderust-analyzer cargo dashu-base 0.4.1 bit/impl#[f32][FloatEncoding]encode().(3, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][Neg]neg().150), Inexactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Inexact#(f32::from_bitsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f32/impl#[f32]from_bits().(0x00000002), Signrust-analyzer cargo dashu-base 0.4.1 sign/Sign#::Positiverust-analyzer cargo dashu-base 0.4.1 sign/Sign#Positive#)); |
| 479 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(f32::encoderust-analyzer cargo dashu-base 0.4.1 bit/impl#[f32][FloatEncoding]encode().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().5, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][Neg]neg().150), Inexactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Inexact#(f32::from_bitsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f32/impl#[f32]from_bits().(0x80000002), Signrust-analyzer cargo dashu-base 0.4.1 sign/Sign#::Positiverust-analyzer cargo dashu-base 0.4.1 sign/Sign#Positive#)); |
| 480 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(f32::encoderust-analyzer cargo dashu-base 0.4.1 bit/impl#[f32][FloatEncoding]encode().(i32::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i32]MAX., 50), Inexactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Inexact#(f32::from_bitsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f32/impl#[f32]from_bits().(0x68000000), Signrust-analyzer cargo dashu-base 0.4.1 sign/Sign#::Positiverust-analyzer cargo dashu-base 0.4.1 sign/Sign#Positive#)); |
| 481 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 482 | f32::encoderust-analyzer cargo dashu-base 0.4.1 bit/impl#[f32][FloatEncoding]encode().(i32::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i32]MAX., -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][Neg]neg().150), |
| 483 | Inexactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Inexact#(f32::from_bitsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f32/impl#[f32]from_bits().(0x04000000), Signrust-analyzer cargo dashu-base 0.4.1 sign/Sign#::Positiverust-analyzer cargo dashu-base 0.4.1 sign/Sign#Positive#) |
| 484 | ); |
| 485 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 486 | f32::encoderust-analyzer cargo dashu-base 0.4.1 bit/impl#[f32][FloatEncoding]encode().(i32::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i32]MAX., -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][Neg]neg().160), |
| 487 | Inexactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Inexact#(f32::from_bitsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f32/impl#[f32]from_bits().(0x00100000), Signrust-analyzer cargo dashu-base 0.4.1 sign/Sign#::Positiverust-analyzer cargo dashu-base 0.4.1 sign/Sign#Positive#) |
| 488 | ); |
| 489 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 490 | f32::encoderust-analyzer cargo dashu-base 0.4.1 bit/impl#[f32][FloatEncoding]encode().(i32::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i32]MAX., -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][Neg]neg().170), |
| 491 | Inexactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Inexact#(f32::from_bitsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f32/impl#[f32]from_bits().(0x00000400), Signrust-analyzer cargo dashu-base 0.4.1 sign/Sign#::Positiverust-analyzer cargo dashu-base 0.4.1 sign/Sign#Positive#) |
| 492 | ); |
| 493 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 494 | f64::encoderust-analyzer cargo dashu-base 0.4.1 bit/impl#[f64][FloatEncoding]encode().(3, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][Neg]neg().1075), |
| 495 | Inexactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Inexact#(f64::from_bitsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f64/impl#[f64]from_bits().(0x0000000000000002), Signrust-analyzer cargo dashu-base 0.4.1 sign/Sign#::Positiverust-analyzer cargo dashu-base 0.4.1 sign/Sign#Positive#) |
| 496 | ); |
| 497 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 498 | f64::encoderust-analyzer cargo dashu-base 0.4.1 bit/impl#[f64][FloatEncoding]encode().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][Neg]neg().5, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][Neg]neg().1075), |
| 499 | Inexactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Inexact#(f64::from_bitsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f64/impl#[f64]from_bits().(0x8000000000000002), Signrust-analyzer cargo dashu-base 0.4.1 sign/Sign#::Positiverust-analyzer cargo dashu-base 0.4.1 sign/Sign#Positive#) |
| 500 | ); |
| 501 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 502 | f64::encoderust-analyzer cargo dashu-base 0.4.1 bit/impl#[f64][FloatEncoding]encode().(i64::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i64]MAX., 500), |
| 503 | Inexactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Inexact#(f64::from_bitsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f64/impl#[f64]from_bits().(0x6320000000000000), Signrust-analyzer cargo dashu-base 0.4.1 sign/Sign#::Positiverust-analyzer cargo dashu-base 0.4.1 sign/Sign#Positive#) |
| 504 | ); |
| 505 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 506 | f64::encoderust-analyzer cargo dashu-base 0.4.1 bit/impl#[f64][FloatEncoding]encode().(i64::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i64]MAX., -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][Neg]neg().1075), |
| 507 | Inexactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Inexact#(f64::from_bitsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f64/impl#[f64]from_bits().(0x00b0000000000000), Signrust-analyzer cargo dashu-base 0.4.1 sign/Sign#::Positiverust-analyzer cargo dashu-base 0.4.1 sign/Sign#Positive#) |
| 508 | ); |
| 509 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 510 | f64::encoderust-analyzer cargo dashu-base 0.4.1 bit/impl#[f64][FloatEncoding]encode().(i64::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i64]MAX., -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][Neg]neg().1095), |
| 511 | Inexactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Inexact#(f64::from_bitsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f64/impl#[f64]from_bits().(0x0000040000000000), Signrust-analyzer cargo dashu-base 0.4.1 sign/Sign#::Positiverust-analyzer cargo dashu-base 0.4.1 sign/Sign#Positive#) |
| 512 | ); |
| 513 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(f64::encoderust-analyzer cargo dashu-base 0.4.1 bit/impl#[f64][FloatEncoding]encode().(i64::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i64]MAX., -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][Neg]neg().1115), Inexactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Inexact#(f64::from_bitsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f64/impl#[f64]from_bits().(0x400000), Signrust-analyzer cargo dashu-base 0.4.1 sign/Sign#::Positiverust-analyzer cargo dashu-base 0.4.1 sign/Sign#Positive#)); |
| 514 | |
| 515 | // other cases |
| 516 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(f32::encoderust-analyzer cargo dashu-base 0.4.1 bit/impl#[f32][FloatEncoding]encode().(1, 0), Exactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Exact#(1f32)); |
| 517 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(f64::encoderust-analyzer cargo dashu-base 0.4.1 bit/impl#[f64][FloatEncoding]encode().(1, 0), Exactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Exact#(1f64)); |
| 518 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(f32::encoderust-analyzer cargo dashu-base 0.4.1 bit/impl#[f32][FloatEncoding]encode().(0x1000000, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][Neg]neg().173), Exactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Exact#(f32::from_bitsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f32/impl#[f32]from_bits().(0x1))); |
| 519 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(f64::encoderust-analyzer cargo dashu-base 0.4.1 bit/impl#[f64][FloatEncoding]encode().(0x40000000000000, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][Neg]neg().1128), Exactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Exact#(f64::from_bitsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f64/impl#[f64]from_bits().(0x1))); |
| 520 | } |
| 521 | } |