-
Notifications
You must be signed in to change notification settings - Fork 4
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
Discussion: float no_std unsupported methods #50
Comments
Including wasm-interpreter/requirements/requirements.sdoc Lines 18 to 26 in 256e3cd
|
So what solution would you guys propose? |
I' immediately aware of https://docs.rs/libm/latest/libm/ and https://crates.io/crates/num-traits . Num internally relies on libm, but it uses the same names like std::f64, thus it is more familiar. Both have a minimal dependency tree, i.e. libm depends on nothing, and num-traits depends only on libm. Other than that, we could implement these by hand. here would be the most basic example for pub fn abs64(x: f64) -> f64 {
f64::from_bits(x.to_bits() & (i64::MAX as u64))
} pub fn abs32(x: f32) -> f32 {
f32::from_bits(x.to_bits() & (i32::MAX as u32))
}
In short, I think it is mostly feasible to implement this by hand, but I believe it would be wise to tap into num-traits and be done with it. |
A recent discussion in issue #50 sparked a need for clarification w/r/t the introduction of dependencies. This refines the requirements to answer the questions w/r/t dependencies. Signed-off-by: wucke13 <[email protected]>
A recent discussion in issue #50 sparked a need for clarification w/r/t the introduction of dependencies. This commit adds requirements to answer the questions w/r/t dependencies. Signed-off-by: wucke13 <[email protected]>
We agreed to use libm, but not num-crates |
As requested by @wucke13 here is the link that talks about some architectures silently altering floats: |
A recent discussion in issue #50 sparked a need for clarification w/r/t the introduction of dependencies. This commit adds requirements to answer the questions w/r/t dependencies. Signed-off-by: wucke13 <[email protected]>
That is an interesting read. IIUC, the TL;DR of it is: bit representation (and especially the case distinctions) for NaN are not handled identical on all architectures. Hence wasmtime chose to implement these themselves. I'm still in favor of just using |
A recent discussion in issue #50 sparked a need for clarification w/r/t the introduction of dependencies. This commit adds requirements to answer the questions w/r/t dependencies. Signed-off-by: wucke13 <[email protected]>
Specifically talking about NaNs, I think it is not a critical problem, but I would keep in mind to fix it later in a similar manner to wasmtime. |
As the title says, there are a few methods for f32 (and I assume for f64, as well), that are only in the std library:
abs
,ceil
,floor
,trunc
,round
,sqrt
andcopysign
.The only alternative I could find, until now, was the libm library. Sadly, it has a major number of 0, which means breaking changes might appear on any new update.
We could lock it at a version or maybe just use from its source what's needed, since licenses are Apache 2 and MIT
The text was updated successfully, but these errors were encountered: