Skip to content
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

Preserve the sign of NaNs when converted to f32? #23

Closed
shaobo-he opened this issue May 8, 2019 · 0 comments · Fixed by #27
Closed

Preserve the sign of NaNs when converted to f32? #23

shaobo-he opened this issue May 8, 2019 · 0 comments · Fixed by #27

Comments

@shaobo-he
Copy link

shaobo-he commented May 8, 2019

Hello,

I noticed that the sign of f32 NaNs are preserved when they are converted to f64 as indicated by this experiment: https://play.rust-lang.org/?version=stable&mode=debug&edition=2015&gist=b23459b96256c673aa6d84ed79a10f50.

But it appears f16 NaNs do not have this behavior. For example, the second assertion fails.

extern crate half;

use half::*;

fn main() {
    let x = f16::from_bits(64513);
    let y = x.to_f32();
    assert!(x.is_sign_negative());
    println!("{}", y);
    assert!(y.is_sign_negative());
}

I couldn't find any useful information about whether the standard specifies this. So I'm not sure if f16 should be consistent with f32 with respect to this behavior.

@shaobo-he shaobo-he changed the title Preserve signedness of NaNs when converted to f32? Preserve the sign of NaNs when converted to f32? May 8, 2019
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

Successfully merging a pull request may close this issue.

1 participant