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

comparison of +0 and -0 gives wrong result #2

Closed
tspiteri opened this issue Dec 29, 2017 · 1 comment
Closed

comparison of +0 and -0 gives wrong result #2

tspiteri opened this issue Dec 29, 2017 · 1 comment

Comments

@tspiteri
Copy link
Contributor

extern crate half;
use half::f16;
fn main() {
    let plus32 = 0f32;
    let minus32 = -plus32;
    let plus16 = f16::from_f32(plus32);
    let minus16 = f16::from_f32(minus32);
    println!("plus32 == minus32 -> {}", plus32 == minus32);
    println!("plus16 == minus16 -> {}", plus16 == minus16);
    println!("plus32.partial_cmp(&minus32) -> {:?}", plus32.partial_cmp(&minus32));
    println!("plus16.partial_cmp(&minus16) -> {:?}", plus16.partial_cmp(&minus16));
}

Output:

plus32 == minus32 -> true
plus16 == minus16 -> false
plus32.partial_cmp(&minus32) -> Some(Equal)
plus16.partial_cmp(&minus16) -> Some(Less)
@tspiteri
Copy link
Contributor Author

Also, partial_cmp incorrectly just compares the inner u16, so all positive numbers are treated as less than all negative numbers.

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

1 participant