Skip to content

from_str_radix incorrect for negative numbers #18692

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
arjantop opened this issue Nov 6, 2014 · 3 comments
Closed

from_str_radix incorrect for negative numbers #18692

arjantop opened this issue Nov 6, 2014 · 3 comments

Comments

@arjantop
Copy link
Contributor

arjantop commented Nov 6, 2014

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);
}
@alexcrichton
Copy link
Member

cc #18659 maybe a dupe (but may not be!)

@nixpulvis
Copy link

Compiling the proposed PR fixes this issue for me.

@alexcrichton
Copy link
Member

Fixed by #18713.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants