Skip to content

Commit

Permalink
seq:enable parsing of hexadecimal floats
Browse files Browse the repository at this point in the history
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 uutils#6935
  • Loading branch information
alexs-sh committed Jan 4, 2025
1 parent 318d5c9 commit d85c9aa
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/uu/seq/src/numberparse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -296,6 +297,14 @@ fn parse_decimal_and_exponent(
/// assert_eq!(actual, expected);
/// ```
fn parse_hexadecimal(s: &str) -> Result<PreciseNumber, ParseNumberError> {
if s.find(['.', 'p', 'P']).is_some() {
floatparse::parse_hexadecimal_float(s)
} else {
parse_hexadecimal_integer(s)
}
}

fn parse_hexadecimal_integer(s: &str) -> Result<PreciseNumber, ParseNumberError> {
let (is_neg, s) = if s.starts_with('-') {
(true, &s[3..])
} else {
Expand Down

0 comments on commit d85c9aa

Please sign in to comment.