Skip to content

Don't propagate NaN for {f32,f64}::{min,max} #1049

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
bjorn3 opened this issue Jun 20, 2020 · 2 comments
Closed

Don't propagate NaN for {f32,f64}::{min,max} #1049

bjorn3 opened this issue Jun 20, 2020 · 2 comments
Labels
C-bug Category: This is a bug. upstream Caused by a dependency

Comments

@bjorn3
Copy link
Member

bjorn3 commented Jun 20, 2020

libstd docs for {f32,f64}::{min,max}:

If one of the arguments is NaN, then the other argument is returned.

Blocked on bytecodealliance/wasmtime#1906

@bjorn3 bjorn3 added the C-bug Category: This is a bug. label Jun 20, 2020
@bjorn3 bjorn3 added the upstream Caused by a dependency label Nov 13, 2020
@eggyal
Copy link
Contributor

eggyal commented Apr 10, 2021

There's not just the matter of NaN propagation (which is documented), but also how -0.0 and +0.0 are compared (which is not): on this point, the llvm.minnum instructions currently used by cg_llvm mirror Cranelift's fmin_pseudo instruction, rather than the fmin instruction that's currently adopted by cg_clif.

cg_clif's existing behaviour appears to follow IEEE754, whereas the current behaviour of rust+llvm (including the documented treatment of NaNs) does not. See rust-lang/rust#83984

@sunfishcode
Copy link
Member

Rust+llvm are following the family of functions known in IEEE 754-2008 as minNum which prefer a number over a NaN and don't define what happens between -0.0 and +0.0 (and has surprising behavior on sNaN).

Cranelift's fmin follows IEEE 754-2019's new minimum and WebAssembly's min, which prefer a NaN over a number and treat -0.0 as less than +0.0 (and have unsurprising behavior on sNaN).

IEEE 754-2019 also defines minimumNumber, which prefers a number over a NaN and treats -0.0 as less than +0.0 (and has unsurprising behavior on sNaN). WebAssembly's MVP was designed before IEEE 754-2019's direction on this issue was known, so it didn't originally add operators for minimumNumber and maximumNumber. Now that IEEE 754-2019 is published, it's a reasonable assumption that WebAssembly should eventually add operators for these.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. upstream Caused by a dependency
Projects
None yet
Development

No branches or pull requests

3 participants