-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
replace the real number trait hierarchy with a single IEEE754 Float
trait
#12281
Comments
cc @bjz |
Agreed. See https://github.com/bjz/ieee754-rs |
yeah, I agree. In fact, It should be made very clear that such is meant to model exactly and only IEEE floats. Its very bad / painful when apis for fundamentally different mathematical models get conflated. (eg look at any discussion that conflates Reals and Floats! :) ) |
I think we have thought about this for a long time, and I don't think we'll ever find a single perfect solution. Have we considered moving all float stuff except Add, Sub, Mul, Div, Mod, Sqrt, FMA to another library? Then different parts of a program can use different math libraries, or there might grow a canonical math library more or less organically? |
We could have |
One issue I can foresee is that things like string conversions need to be implemented in the std, and they rely on some float functions. |
IEEE Floats are something that is better off having some amount of compiler support, for all the specified operations of the standard. This is because a) it should exploit llvm compilation support b) you really want to make sure that any float operations will (by default) retain meaning during optimization |
@cartazio so in your mind, an IEEE float API belongs in libstd? |
@bjz, Floats have a very very precise spec. How are you planning to define all the IEEE Float ops in such a way that it can be understood by both Rust and LLVM wrt suitable/correct optimizations? Are you planning on using the rust support for inline LLVM IR? |
What support? (@jensnockert: you had a branch implementing inline LLVM didn't you? Maybe we could merge it behind a feature gate, similar to |
@cartazio Indeed. I have begun sketching an API out in https://github.com/bjz/ieee754-rs/blob/master/src/lib.rs, but it will be a big effort to fully implement it. One issue is, according to @strcat, that LLVM does incorrect optimisations on floats, for example assuming that operations are commutative when they are not. |
@bjz yes, and most of those operations (as I understand it) should have an LLVM IR analogue operation. (though doing a software implementation would be valuable too! ) |
@huonw theres no way to have peformant float ops as a userland lib if it can't hook into generating the right LLVM / compiler IR primops :) |
so if having special inline llvm IR is something Rust can robustly support going forward, theres very very little cost to having all the float stuff be userland for now I guess. (though it does make providing any floating point analysis/optmization support in the rust Compiler a bit harder to add! ) |
(I was just pointing out that we don't have support yet.) |
oh ok. :) |
@huonw: I'll take a look at it, when I did it, there were no feature gates, and I'm pretty sure everyone involved didn't want to unleash such terror on the language. But with feature gates, it could help the few people who need it, like the libstd implementors. @cartazio: Yeah, but that's only a few. Most of IEEE 754-2008 has to be implemented in software. |
fair enough, I guess most of the hardware support for the fancy functions just gives a decent intial estimate for a fixed iteration count newton method solvers or special lookup tables plus interpolation, so i mispoke before (long weekend, lots of travel) |
Should we anticipate there being more hardware support available in the future though? |
I doubt it, modern architectures seem to have less hardware than older ones. x87 did everything in microcode, SSE had hardware only for the basic ops (neg, add, sub, mul, div, sqrt, round), Itanium had hardware only for FMA and rounding. |
@bjz: The parts not supported properly by LLVM are the floating point rounding mode, signalling NaN and floating point exceptions. There's no way to work around this in Rust. It has to be implemented in LLVM. The optimizations changing results are only performed if |
In my opinion, the standard library support should simply look like https://github.com/thestinger/rust-core/blob/master/core/f64.rs. At most, these should all be moved to a single |
Agreed. By the way, to do the best job of an |
Closing, this is done now. |
…icola Increase defalt chalk overflow depth to match max solver size TBC: - rust-lang#12279: ok above 480 - ~~rust-lang#12182~~ - ~~rust-lang#12095~~ - rust-lang#11902: ok above 350 - ~~rust-lang#11668~~ - rust-lang#11370: ok above 450 - rust-lang#9754: probably ok above 250 (!), and the code in cause and branch are gone Closes rust-lang#12279 Closes rust-lang#11902 Closes rust-lang#11370 Closes rust-lang#9754
A proper mathematical numeric hierarchy can be left to another library. I think all we need in the standard library is the ability to abstract code across different sizes of IEEE754 floating point numbers. I don't think trying to support code that's generic across both integers and floating point numbers is worth attempting in the standard library either beyond the basic operator overloads.
The text was updated successfully, but these errors were encountered: