Skip to content

from_str_radix incorrect for negative numbers #18692

Closed
@arjantop

Description

@arjantop

Encoding any negative number with to_str_radix does not produce the correct result when decoding with from_str_radix since (my guess) #18536.

use std::f32::{from_str_hex, to_str_hex};
use std::num::from_str_radix;

fn main() {
    let x = -1.0f32;
    let h = to_str_hex(x);
    println!("hex = {}", h);
    assert_eq!(from_str_radix::<f32>(h.as_slice(), 16).unwrap(), x);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions