Skip to content

[BUG] Assertion failure on parsing hexadecimal floats #87

@xTibor

Description

@xTibor

Description

When parsing C-style hexadecimal floats (C_HEX_STRING/HEX_FLOAT) Lexical currently throws the following assertion failure in debug mode:

thread 'main' panicked at 'assertion failed: format.mantissa_radix() == format.exponent_base()', /home/tibor/.cargo/registry/src/mygithub.libinneed.workers.dev-1ecc6299db9ec823/lexical-parse-float-0.8.5/src/number.rs:60:9

Prerequisites

  • Rust version: rustc 1.64.0-nightly (3924dac7b 2022-07-29)
  • lexical version: 6.1.1
  • lexical compilation features used: ["parse-floats", "radix", "power-of-two", "format"]

Test case

fn main() {
    let c_hex_float = "0x12.34p5"; // 582.5 in decimal

    const FORMAT: u128 = lexical::format::C_HEX_STRING;
    let options = &lexical::parse_float_options::HEX_FLOAT;

    let (result, _) =
        lexical::parse_partial_with_options::<f32, _, FORMAT>(c_hex_float, options).unwrap();

    println!("{}: {}", c_hex_float, result);
}

Additional Context

I encountered this issue while working on reimplementing the strtof and strtod functions in Relibc (Redox C library) using Lexical.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingnormal priorityNormal Priority

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions