From f869213aa863c2403719d0f7fc3d88986419e193 Mon Sep 17 00:00:00 2001 From: Alexander Shirokov Date: Sat, 14 Dec 2024 15:34:46 +0100 Subject: [PATCH] seq:enable parsing of hexadecimal floats Turn on the float parser. Now it's possible to use hexadecimal floats as parameters. For example, cargo run -- 0x1p-1 3 0.5 1.5 2.5 Issue #6935 --- src/uu/seq/src/numberparse.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/uu/seq/src/numberparse.rs b/src/uu/seq/src/numberparse.rs index c8dec018041..1c5902633a7 100644 --- a/src/uu/seq/src/numberparse.rs +++ b/src/uu/seq/src/numberparse.rs @@ -16,6 +16,7 @@ use num_traits::Num; use num_traits::Zero; use crate::extendedbigdecimal::ExtendedBigDecimal; +use crate::floatparse; use crate::number::PreciseNumber; /// An error returned when parsing a number fails. @@ -296,6 +297,14 @@ fn parse_decimal_and_exponent( /// assert_eq!(actual, expected); /// ``` fn parse_hexadecimal(s: &str) -> Result { + if s.find(['.', 'p', 'P']).is_some() { + floatparse::parse_hexadecimal_float(s) + } else { + parse_hexadecimal_integer(s) + } +} + +fn parse_hexadecimal_integer(s: &str) -> Result { let (is_neg, s) = if s.starts_with('-') { (true, &s[3..]) } else {