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

replace the real number trait hierarchy with a single IEEE754 Float trait #12281

Closed
thestinger opened this issue Feb 15, 2014 · 25 comments
Closed

Comments

@thestinger
Copy link
Contributor

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.

@thestinger
Copy link
Contributor Author

cc @bjz

@brendanzab
Copy link
Member

Agreed. See https://github.com/bjz/ieee754-rs

@brendanzab
Copy link
Member

cc. @cartazio, @jensnockert, #10387

@cartazio
Copy link
Contributor

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! :) )

@auroranockert
Copy link
Contributor

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?

@brendanzab
Copy link
Member

We could have libfloat. But I'm not sure if that is excessive. I definitely think that Float and the other numeric traits should not be automatically exported in the prelude, and using the std::num::* functions should be the normal way of doing mathematics.

@brendanzab
Copy link
Member

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.

@cartazio
Copy link
Contributor

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

@brendanzab
Copy link
Member

@cartazio so in your mind, an IEEE float API belongs in libstd?

@cartazio
Copy link
Contributor

@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?

@huonw
Copy link
Member

huonw commented Feb 17, 2014

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 asm?)

@brendanzab
Copy link
Member

Floats have a very very precise spec

@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.

@cartazio
Copy link
Contributor

@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! )

@cartazio
Copy link
Contributor

@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 :)

@cartazio
Copy link
Contributor

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! )

@huonw
Copy link
Member

huonw commented Feb 17, 2014

(I was just pointing out that we don't have support yet.)

@cartazio
Copy link
Contributor

oh ok. :)
so in the mean time, hardware supported floats need to have all their operations baked into rust :)

@auroranockert
Copy link
Contributor

@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.

@cartazio
Copy link
Contributor

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)

@brendanzab
Copy link
Member

Should we anticipate there being more hardware support available in the future though?

@auroranockert
Copy link
Contributor

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.

bors added a commit that referenced this issue Feb 18, 2014
This is part of the effort to simplify `std::num`, as tracked in issue #10387. It is also a step towards a proper IEEE-754 trait (see #12281).
@thestinger
Copy link
Contributor Author

@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 fpmath metadata is used to mark the permitted error or some subset of the fast-math flags are enabled via metadata.

@thestinger
Copy link
Contributor Author

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 Float trait for abstracting over different sizes of IEEE754 floats but no attempt should be made to include them in a numeric hierarchy.

@brendanzab
Copy link
Member

Agreed.

By the way, to do the best job of an IEEE 754 trait, associated items would be most appreciated so that we can express LogBFormat and IntegralFormat outside of trait type parameters. fn foo<LB, I, Float<LB, I>>(...) would be a massive pain.

@alexcrichton
Copy link
Member

Closing, this is done now.

bors added a commit to rust-lang-ci/rust that referenced this issue Jul 25, 2022
…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
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

6 participants