| 1 | use craterust-analyzer cargo fast-float2 0.2.3 crate/::commonrust-analyzer cargo fast-float2 0.2.3 common/::{is_8digitsrust-analyzer cargo fast-float2 0.2.3 common/is_8digits()., AsciiStrrust-analyzer cargo fast-float2 0.2.3 common/AsciiStr#, ByteSlicerust-analyzer cargo fast-float2 0.2.3 common/ByteSlice#}; |
| 2 | use craterust-analyzer cargo fast-float2 0.2.3 crate/::floatrust-analyzer cargo fast-float2 0.2.3 float/::Floatrust-analyzer cargo fast-float2 0.2.3 float/Float#; |
| 3 | |
| 4 | const MIN_19DIGIT_INTrust-analyzer cargo fast-float2 0.2.3 number/MIN_19DIGIT_INT.: u64 = 100_0000_0000_0000_0000; |
| 5 | |
| 6 | #[allow(clippy::unreadable_literal)] |
| 7 | pub const INT_POW10rust-analyzer cargo fast-float2 0.2.3 number/INT_POW10.: [u64; 16] = [ |
| 8 | 1, |
| 9 | 10, |
| 10 | 100, |
| 11 | 1000, |
| 12 | 10000, |
| 13 | 100000, |
| 14 | 1000000, |
| 15 | 10000000, |
| 16 | 100000000, |
| 17 | 1000000000, |
| 18 | 10000000000, |
| 19 | 100000000000, |
| 20 | 1000000000000, |
| 21 | 10000000000000, |
| 22 | 100000000000000, |
| 23 | 1000000000000000, |
| 24 | ]; |
| 25 | |
| 26 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:)] |
| 27 | pub struct Numberrust-analyzer cargo fast-float2 0.2.3 number/Number# { |
| 28 | pub exponentrust-analyzer cargo fast-float2 0.2.3 number/Number#exponent.: i64, |
| 29 | pub mantissarust-analyzer cargo fast-float2 0.2.3 number/Number#mantissa.: u64, |
| 30 | pub negativerust-analyzer cargo fast-float2 0.2.3 number/Number#negative.: bool, |
| 31 | pub many_digitsrust-analyzer cargo fast-float2 0.2.3 number/Number#many_digits.: bool, |
| 32 | } |
| 33 | |
| 34 | impl Numberrust-analyzer cargo fast-float2 0.2.3 number/Number# { |
| 35 | #[inline] |
| 36 | fn is_fast_pathrust-analyzer cargo fast-float2 0.2.3 number/impl#[Number]is_fast_path().<F: Floatrust-analyzer cargo fast-float2 0.2.3 float/Float#>(&self) -> bool { |
| 37 | F::MIN_EXPONENT_FAST_PATHrust-analyzer cargo fast-float2 0.2.3 float/Float#MIN_EXPONENT_FAST_PATH. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialOrd<Self>`]le().self.exponentrust-analyzer cargo fast-float2 0.2.3 number/Number#exponent. |
| 38 | && self.exponentrust-analyzer cargo fast-float2 0.2.3 number/Number#exponent. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialOrd<Self>`]le().F::MAX_EXPONENT_DISGUISED_FAST_PATHrust-analyzer cargo fast-float2 0.2.3 float/Float#MAX_EXPONENT_DISGUISED_FAST_PATH. |
| 39 | && self.mantissarust-analyzer cargo fast-float2 0.2.3 number/Number#mantissa. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]le().F::MAX_MANTISSA_FAST_PATHrust-analyzer cargo fast-float2 0.2.3 float/Float#MAX_MANTISSA_FAST_PATH. |
| 40 | && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.many_digitsrust-analyzer cargo fast-float2 0.2.3 number/Number#many_digits. |
| 41 | } |
| 42 | |
| 43 | #[inline] |
| 44 | pub fn try_fast_pathrust-analyzer cargo fast-float2 0.2.3 number/impl#[Number]try_fast_path().<F: Floatrust-analyzer cargo fast-float2 0.2.3 float/Float#>(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<F> { |
| 45 | if self.is_fast_pathrust-analyzer cargo fast-float2 0.2.3 number/impl#[Number]is_fast_path().::<F>() { |
| 46 | let mut value = if self.exponentrust-analyzer cargo fast-float2 0.2.3 number/Number#exponent. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialOrd<Self>`]le().F::MAX_EXPONENT_FAST_PATHrust-analyzer cargo fast-float2 0.2.3 float/Float#MAX_EXPONENT_FAST_PATH. { |
| 47 | // normal fast path |
| 48 | let value = F::from_u64rust-analyzer cargo fast-float2 0.2.3 float/Float#from_u64().(self.mantissarust-analyzer cargo fast-float2 0.2.3 number/Number#mantissa.); |
| 49 | if self.exponentrust-analyzer cargo fast-float2 0.2.3 number/Number#exponent. 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 { |
| 50 | value rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Div#div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Div#div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Div#div().F::pow10_fast_pathrust-analyzer cargo fast-float2 0.2.3 float/Float#pow10_fast_path().((-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][Neg]neg().self.exponentrust-analyzer cargo fast-float2 0.2.3 number/Number#exponent.) as usize) |
| 51 | } else { |
| 52 | value rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().F::pow10_fast_pathrust-analyzer cargo fast-float2 0.2.3 float/Float#pow10_fast_path().(self.exponentrust-analyzer cargo fast-float2 0.2.3 number/Number#exponent. as usize) |
| 53 | } |
| 54 | } else { |
| 55 | // disguised fast path |
| 56 | let shift = self.exponentrust-analyzer cargo fast-float2 0.2.3 number/Number#exponent. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Sub<Self>`]sub().F::MAX_EXPONENT_FAST_PATHrust-analyzer cargo fast-float2 0.2.3 float/Float#MAX_EXPONENT_FAST_PATH.; |
| 57 | let mantissa = self.mantissarust-analyzer cargo fast-float2 0.2.3 number/Number#mantissa..checked_mulrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]checked_mul().(INT_POW10rust-analyzer cargo fast-float2 0.2.3 number/INT_POW10.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().shift as usize]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().; |
| 58 | if mantissa 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().F::MAX_MANTISSA_FAST_PATHrust-analyzer cargo fast-float2 0.2.3 float/Float#MAX_MANTISSA_FAST_PATH. { |
| 59 | return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 60 | } |
| 61 | F::from_u64rust-analyzer cargo fast-float2 0.2.3 float/Float#from_u64().(mantissa) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().F::pow10_fast_pathrust-analyzer cargo fast-float2 0.2.3 float/Float#pow10_fast_path().(F::MAX_EXPONENT_FAST_PATHrust-analyzer cargo fast-float2 0.2.3 float/Float#MAX_EXPONENT_FAST_PATH. as usize) |
| 62 | }; |
| 63 | if self.negativerust-analyzer cargo fast-float2 0.2.3 number/Number#negative. { |
| 64 | value = -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Neg#neg().value; |
| 65 | } |
| 66 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(value) |
| 67 | } else { |
| 68 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | #[inline] |
| 74 | fn parse_8digitsrust-analyzer cargo fast-float2 0.2.3 number/parse_8digits().(mut v: u64) -> u64 { |
| 75 | const MASKrust-analyzer cargo fast-float2 0.2.3 number/MASK.: u64 = 0x0000_00FF_0000_00FF; |
| 76 | const MUL1rust-analyzer cargo fast-float2 0.2.3 number/MUL1.: u64 = 0x000F_4240_0000_0064; |
| 77 | const MUL2rust-analyzer cargo fast-float2 0.2.3 number/MUL2.: u64 = 0x0000_2710_0000_0001; |
| 78 | v rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`SubAssign<Self>`]sub_assign().0x3030_3030_3030_3030; |
| 79 | v = (v rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().10) 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().(v 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().8); // will not overflow, fits in 63 bits |
| 80 | let v1 = (v 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().MASKrust-analyzer cargo fast-float2 0.2.3 number/MASK.).wrapping_mulrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]wrapping_mul().(MUL1rust-analyzer cargo fast-float2 0.2.3 number/MUL1.); |
| 81 | let v2 = ((v 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().16) 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().MASKrust-analyzer cargo fast-float2 0.2.3 number/MASK.).wrapping_mulrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]wrapping_mul().(MUL2rust-analyzer cargo fast-float2 0.2.3 number/MUL2.); |
| 82 | ((v1.wrapping_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]wrapping_add().(v2) 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().32) as u32) as u64 |
| 83 | } |
| 84 | |
| 85 | #[inline] |
| 86 | fn try_parse_digitsrust-analyzer cargo fast-float2 0.2.3 number/try_parse_digits().(s: &mut AsciiStrrust-analyzer cargo fast-float2 0.2.3 common/AsciiStr#<'_>, x: &mut u64) { |
| 87 | s.parse_digitsrust-analyzer cargo fast-float2 0.2.3 common/impl#[`AsciiStr<'a>`]parse_digits().(|digit| { |
| 88 | // overflows to be handled later |
| 89 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().x = x.wrapping_mulrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]wrapping_mul().(10).wrapping_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]wrapping_add().(digit as u64); |
| 90 | }); |
| 91 | } |
| 92 | |
| 93 | #[inline] |
| 94 | fn try_parse_19digitsrust-analyzer cargo fast-float2 0.2.3 number/try_parse_19digits().(s: &mut AsciiStrrust-analyzer cargo fast-float2 0.2.3 common/AsciiStr#<'_>, x: &mut u64) { |
| 95 | while *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().x rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]lt().MIN_19DIGIT_INTrust-analyzer cargo fast-float2 0.2.3 number/MIN_19DIGIT_INT. { |
| 96 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(digit) = s.try_read_digitrust-analyzer cargo fast-float2 0.2.3 common/impl#[`AsciiStr<'a>`]try_read_digit().() { |
| 97 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().x = (*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().x rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().10) 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().digit as u64; // no overflows here |
| 98 | } else { |
| 99 | break; |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | #[inline] |
| 105 | fn try_parse_8digitsrust-analyzer cargo fast-float2 0.2.3 number/try_parse_8digits().(s: &mut AsciiStrrust-analyzer cargo fast-float2 0.2.3 common/AsciiStr#<'_>, x: &mut u64) { |
| 106 | // may cause overflows, to be handled later |
| 107 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(v) = s.try_read_u64rust-analyzer cargo fast-float2 0.2.3 common/impl#[`AsciiStr<'a>`]try_read_u64().() { |
| 108 | if is_8digitsrust-analyzer cargo fast-float2 0.2.3 common/is_8digits().(v) { |
| 109 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().x = x.wrapping_mulrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]wrapping_mul().(1_0000_0000).wrapping_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]wrapping_add().(parse_8digitsrust-analyzer cargo fast-float2 0.2.3 number/parse_8digits().(v)); |
| 110 | // SAFETY: safe since there is at least 8 bytes from `try_read_u64`. |
| 111 | unsafe { s.step_byrust-analyzer cargo fast-float2 0.2.3 common/impl#[`AsciiStr<'a>`]step_by().(8) }; |
| 112 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(v) = s.try_read_u64rust-analyzer cargo fast-float2 0.2.3 common/impl#[`AsciiStr<'a>`]try_read_u64().() { |
| 113 | if is_8digitsrust-analyzer cargo fast-float2 0.2.3 common/is_8digits().(v) { |
| 114 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().x = x.wrapping_mulrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]wrapping_mul().(1_0000_0000).wrapping_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]wrapping_add().(parse_8digitsrust-analyzer cargo fast-float2 0.2.3 number/parse_8digits().(v)); |
| 115 | // SAFETY: safe since there is at least 8 bytes from `try_read_u64`. |
| 116 | unsafe { s.step_byrust-analyzer cargo fast-float2 0.2.3 common/impl#[`AsciiStr<'a>`]step_by().(8) }; |
| 117 | } |
| 118 | } |
| 119 | } |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | #[inline] |
| 124 | fn parse_scientificrust-analyzer cargo fast-float2 0.2.3 number/parse_scientific().(s: &mut AsciiStrrust-analyzer cargo fast-float2 0.2.3 common/AsciiStr#<'_>) -> i64 { |
| 125 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().s.first_is2rust-analyzer cargo fast-float2 0.2.3 common/impl#[`AsciiStr<'a>`]first_is2().(b'e', b'E') { |
| 126 | return 0; |
| 127 | } |
| 128 | |
| 129 | // the first character is 'e'/'E' and scientific mode is enabled |
| 130 | let start = *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().s; |
| 131 | // SAFETY: safe since there is at least 1 character which is `e` or `E` |
| 132 | unsafe { s.steprust-analyzer cargo fast-float2 0.2.3 common/impl#[`AsciiStr<'a>`]step().() }; |
| 133 | let mut exp_num = 0_i64; |
| 134 | let mut neg_exp = false; |
| 135 | if s.first_is2rust-analyzer cargo fast-float2 0.2.3 common/impl#[`AsciiStr<'a>`]first_is2().(b'-', b'+') { |
| 136 | neg_exp = s.first_isrust-analyzer cargo fast-float2 0.2.3 common/impl#[`AsciiStr<'a>`]first_is().(b'-'); |
| 137 | // SAFETY: safe since there's at least 1 character in the buffer |
| 138 | unsafe { s.steprust-analyzer cargo fast-float2 0.2.3 common/impl#[`AsciiStr<'a>`]step().() }; |
| 139 | } |
| 140 | if s.first_is_digitrust-analyzer cargo fast-float2 0.2.3 common/impl#[`AsciiStr<'a>`]first_is_digit().() { |
| 141 | s.parse_digitsrust-analyzer cargo fast-float2 0.2.3 common/impl#[`AsciiStr<'a>`]parse_digits().(|digit| { |
| 142 | if exp_num 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().0x10000 { |
| 143 | exp_num = 10 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Mul<Self>`]mul().exp_num rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Add<Self>`]add().digit as i64; // no overflows here |
| 144 | } |
| 145 | }); |
| 146 | if neg_exp { |
| 147 | -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][Neg]neg().exp_num |
| 148 | } else { |
| 149 | exp_num |
| 150 | } |
| 151 | } else { |
| 152 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().s = start; // ignore 'e' and return back |
| 153 | 0 |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | #[inline] |
| 158 | pub fn parse_numberrust-analyzer cargo fast-float2 0.2.3 number/parse_number().(s: &[u8]) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<(Numberrust-analyzer cargo fast-float2 0.2.3 number/Number#, usize)> { |
| 159 | if s.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().() { |
| 160 | return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 161 | } |
| 162 | |
| 163 | let mut s = AsciiStrrust-analyzer cargo fast-float2 0.2.3 common/AsciiStr#::newrust-analyzer cargo fast-float2 0.2.3 common/impl#[`AsciiStr<'a>`]new().(s); |
| 164 | let start = s; |
| 165 | |
| 166 | // handle optional +/- sign |
| 167 | let mut negative = false; |
| 168 | if s.step_ifrust-analyzer cargo fast-float2 0.2.3 common/impl#[`AsciiStr<'a>`]step_if().(b'-') { |
| 169 | negative = true; |
| 170 | if s.is_emptyrust-analyzer cargo fast-float2 0.2.3 common/impl#[`AsciiStr<'a>`]is_empty().() { |
| 171 | return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 172 | } |
| 173 | } else if s.step_ifrust-analyzer cargo fast-float2 0.2.3 common/impl#[`AsciiStr<'a>`]step_if().(b'+') && s.is_emptyrust-analyzer cargo fast-float2 0.2.3 common/impl#[`AsciiStr<'a>`]is_empty().() { |
| 174 | return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 175 | } |
| 176 | debug_assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/debug_assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().s.is_emptyrust-analyzer cargo fast-float2 0.2.3 common/impl#[`AsciiStr<'a>`]is_empty().(), "should not have empty buffer after sign checks"); |
| 177 | |
| 178 | // parse initial digits before dot |
| 179 | let mut mantissa = 0_u64; |
| 180 | let digits_start = s; |
| 181 | try_parse_digitsrust-analyzer cargo fast-float2 0.2.3 number/try_parse_digits().(&mut s, &mut mantissa); |
| 182 | let mut n_digits = s.offset_fromrust-analyzer cargo fast-float2 0.2.3 common/impl#[`AsciiStr<'a>`]offset_from().(&digits_start); |
| 183 | |
| 184 | // handle dot with the following digits |
| 185 | let mut n_after_dot = 0; |
| 186 | let mut exponent = 0_i64; |
| 187 | let int_end = s; |
| 188 | if s.step_ifrust-analyzer cargo fast-float2 0.2.3 common/impl#[`AsciiStr<'a>`]step_if().(b'.') { |
| 189 | let before = s; |
| 190 | try_parse_8digitsrust-analyzer cargo fast-float2 0.2.3 number/try_parse_8digits().(&mut s, &mut mantissa); |
| 191 | try_parse_digitsrust-analyzer cargo fast-float2 0.2.3 number/try_parse_digits().(&mut s, &mut mantissa); |
| 192 | n_after_dot = s.offset_fromrust-analyzer cargo fast-float2 0.2.3 common/impl#[`AsciiStr<'a>`]offset_from().(&before); |
| 193 | exponent = -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][Neg]neg().n_after_dot as i64; |
| 194 | } |
| 195 | |
| 196 | n_digits rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`AddAssign<Self>`]add_assign().n_after_dot; |
| 197 | if n_digits rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialEq<Self>`]eq().0 { |
| 198 | return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 199 | } |
| 200 | |
| 201 | // handle scientific format |
| 202 | let exp_number = parse_scientificrust-analyzer cargo fast-float2 0.2.3 number/parse_scientific().(&mut s); |
| 203 | exponent rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`AddAssign<Self>`]add_assign().exp_number; |
| 204 | |
| 205 | let len = s.offset_fromrust-analyzer cargo fast-float2 0.2.3 common/impl#[`AsciiStr<'a>`]offset_from().(&start) as usize; |
| 206 | |
| 207 | // handle uncommon case with many digits |
| 208 | if n_digits rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialOrd<Self>`]le().19 { |
| 209 | return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(( |
| 210 | Numberrust-analyzer cargo fast-float2 0.2.3 number/Number# { |
| 211 | exponentrust-analyzer cargo fast-float2 0.2.3 number/Number#exponent., |
| 212 | mantissarust-analyzer cargo fast-float2 0.2.3 number/Number#mantissa., |
| 213 | negativerust-analyzer cargo fast-float2 0.2.3 number/Number#negative., |
| 214 | many_digitsrust-analyzer cargo fast-float2 0.2.3 number/Number#many_digits.: false, |
| 215 | }, |
| 216 | len, |
| 217 | )); |
| 218 | } |
| 219 | |
| 220 | n_digits rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`SubAssign<Self>`]sub_assign().19; |
| 221 | let mut many_digits = false; |
| 222 | let mut p = digits_start; |
| 223 | while p.first_is2rust-analyzer cargo fast-float2 0.2.3 common/impl#[`AsciiStr<'a>`]first_is2().(b'0', b'.') { |
| 224 | // SAFETY: safe since there's at least 1 element that is `0` or `.`. |
| 225 | let byte = unsafe { p.first_uncheckedrust-analyzer cargo fast-float2 0.2.3 common/impl#[`AsciiStr<'a>`]first_unchecked().() }; |
| 226 | // '0' = b'.' + 2 |
| 227 | n_digits rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][`SubAssign<Self>`]sub_assign().byte.saturating_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u8]saturating_sub().(b'0' rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u8][`Sub<Self>`]sub().1) as isize; |
| 228 | // SAFETY: safe since there's at least 1 element from the `first_is2` check. |
| 229 | unsafe { p.steprust-analyzer cargo fast-float2 0.2.3 common/impl#[`AsciiStr<'a>`]step().() }; |
| 230 | } |
| 231 | if n_digits rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[isize][`PartialOrd<Self>`]gt().0 { |
| 232 | // at this point we have more than 19 significant digits, let's try again |
| 233 | many_digits = true; |
| 234 | mantissa = 0; |
| 235 | let mut s = digits_start; |
| 236 | try_parse_19digitsrust-analyzer cargo fast-float2 0.2.3 number/try_parse_19digits().(&mut s, &mut mantissa); |
| 237 | exponent = if mantissa rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]ge().MIN_19DIGIT_INTrust-analyzer cargo fast-float2 0.2.3 number/MIN_19DIGIT_INT. { |
| 238 | int_end.offset_fromrust-analyzer cargo fast-float2 0.2.3 common/impl#[`AsciiStr<'a>`]offset_from().(&s) // big int |
| 239 | } else { |
| 240 | // SAFETY: safe since `s` is at the digits start, so we have |
| 241 | // at least 1 digit from `ndigits > 0`. |
| 242 | debug_assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/debug_assert!!(s.first_isrust-analyzer cargo fast-float2 0.2.3 common/impl#[`AsciiStr<'a>`]first_is().(b'.'), "first character for the fraction must be a decimal"); |
| 243 | unsafe { s.steprust-analyzer cargo fast-float2 0.2.3 common/impl#[`AsciiStr<'a>`]step().() }; // fractional component, skip the '.' |
| 244 | let before = s; |
| 245 | try_parse_19digitsrust-analyzer cargo fast-float2 0.2.3 number/try_parse_19digits().(&mut s, &mut mantissa); |
| 246 | -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[isize][Neg]neg().s.offset_fromrust-analyzer cargo fast-float2 0.2.3 common/impl#[`AsciiStr<'a>`]offset_from().(&before) |
| 247 | } as i64; |
| 248 | exponent rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`AddAssign<Self>`]add_assign().exp_number; // add back the explicit part |
| 249 | } |
| 250 | |
| 251 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(( |
| 252 | Numberrust-analyzer cargo fast-float2 0.2.3 number/Number# { |
| 253 | exponentrust-analyzer cargo fast-float2 0.2.3 number/Number#exponent., |
| 254 | mantissarust-analyzer cargo fast-float2 0.2.3 number/Number#mantissa., |
| 255 | negativerust-analyzer cargo fast-float2 0.2.3 number/Number#negative., |
| 256 | many_digitsrust-analyzer cargo fast-float2 0.2.3 number/Number#many_digits., |
| 257 | }, |
| 258 | len, |
| 259 | )) |
| 260 | } |
| 261 | |
| 262 | #[inline] |
| 263 | pub fn parse_inf_nanrust-analyzer cargo fast-float2 0.2.3 number/parse_inf_nan().<F: Floatrust-analyzer cargo fast-float2 0.2.3 float/Float#>(s: &[u8]) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<(F, usize)> { |
| 264 | fn parse_inf_restrust-analyzer cargo fast-float2 0.2.3 number/parse_inf_rest().(s: &[u8]) -> usize { |
| 265 | if s.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().8 && s[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().3..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..eq_ignore_caserust-analyzer cargo fast-float2 0.2.3 common/ByteSlice#eq_ignore_case().(b"inity") { |
| 266 | 8 |
| 267 | } else { |
| 268 | 3 |
| 269 | } |
| 270 | } |
| 271 | if s.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().3 { |
| 272 | if s.eq_ignore_caserust-analyzer cargo fast-float2 0.2.3 common/ByteSlice#eq_ignore_case().(b"nan") { |
| 273 | return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((F::NANrust-analyzer cargo fast-float2 0.2.3 float/Float#NAN., 3)); |
| 274 | } else if s.eq_ignore_caserust-analyzer cargo fast-float2 0.2.3 common/ByteSlice#eq_ignore_case().(b"inf") { |
| 275 | return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((F::INFINITYrust-analyzer cargo fast-float2 0.2.3 float/Float#INFINITY., parse_inf_restrust-analyzer cargo fast-float2 0.2.3 number/parse_inf_rest().(s))); |
| 276 | } else if s.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().4 { |
| 277 | if s[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). 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().b'+' { |
| 278 | let s = s.advancerust-analyzer cargo fast-float2 0.2.3 common/ByteSlice#advance().(1); |
| 279 | if s.eq_ignore_caserust-analyzer cargo fast-float2 0.2.3 common/ByteSlice#eq_ignore_case().(b"nan") { |
| 280 | return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((F::NANrust-analyzer cargo fast-float2 0.2.3 float/Float#NAN., 4)); |
| 281 | } else if s.eq_ignore_caserust-analyzer cargo fast-float2 0.2.3 common/ByteSlice#eq_ignore_case().(b"inf") { |
| 282 | return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((F::INFINITYrust-analyzer cargo fast-float2 0.2.3 float/Float#INFINITY., 1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().parse_inf_restrust-analyzer cargo fast-float2 0.2.3 number/parse_inf_rest().(s))); |
| 283 | } |
| 284 | } else if s[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). 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().b'-' { |
| 285 | let s = s.advancerust-analyzer cargo fast-float2 0.2.3 common/ByteSlice#advance().(1); |
| 286 | if s.eq_ignore_caserust-analyzer cargo fast-float2 0.2.3 common/ByteSlice#eq_ignore_case().(b"nan") { |
| 287 | return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((F::NEG_NANrust-analyzer cargo fast-float2 0.2.3 float/Float#NEG_NAN., 4)); |
| 288 | } else if s.eq_ignore_caserust-analyzer cargo fast-float2 0.2.3 common/ByteSlice#eq_ignore_case().(b"inf") { |
| 289 | return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((F::NEG_INFINITYrust-analyzer cargo fast-float2 0.2.3 float/Float#NEG_INFINITY., 1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().parse_inf_restrust-analyzer cargo fast-float2 0.2.3 number/parse_inf_rest().(s))); |
| 290 | } |
| 291 | } |
| 292 | } |
| 293 | } |
| 294 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 295 | } |