rust-num / num-traits

Numeric traits for generic mathematics in Rust
Apache License 2.0
731 stars 135 forks source link

Why does the Float trait not inherit FloatConst? #156

Closed stijnfrishert closed 4 years ago

stijnfrishert commented 4 years ago

Makes sense to me that every Float should be able to provide values such as π by default.

(Once again, pretty new to Rust, so if this doesn't make any sense I'd love to learn why not too)

cuviper commented 4 years ago

History. The Float trait existed before FloatConst, and it would be a breaking change to add new constraints now.

We could do that with a bump to the semantic version, but I've been loath to consider that since these traits are often in the public API of other crates. That would make it a breaking change for those crates to adopt new num-traits, so the ecosystem upgrade would be painful.

stijnfrishert commented 4 years ago

Ah sure, I get that. Too bad the ecosystem has developed in such a way that it makes it hard for popular crates like these to upgrade.

In any case, I guess this can be closed. Thanks for explaining.

cuviper commented 4 years ago

FWIW, it should be easy to define your own combined trait for convenience, like:

use num_traits::{Float, FloatConst};
trait MyFloat: Float + FloatConst {}
impl<T: Float + FloatConst> MyFloat for T {}
stijnfrishert commented 4 years ago

Yeah, that might be a good idea if my codebase grows larger. For now just playing around, but thank you for the tip!