-
Notifications
You must be signed in to change notification settings - Fork 148
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
Add a trait for floating-point constants #220
Conversation
Thanks for this!
I don't like either name if we export the at the top level of
I guess the ones you mean are
The nice thing about having them totally separate is that this isn't a breaking change to add it. If |
Question 1. I agree that the name Constant is too general when considered in the context of the root module. I re-exported the trait in order to follow the conventions that I saw in the code: you keep all the modules public but at the same time re-export all their contents. If we don’t re-export Let’s see how different versions might look: use num_traits::float::{Float, Const};
fn foo1<T>(bar: T) -> T where T: Float + Const {
bar + T::pi() // or Const::pi()
}
use num_traits::float::{Float, Constant};
fn foo2<T>(bar: T) -> T where T: Float + Constant {
bar + T::pi() // or Constant::pi()
}
use num_traits::{Float, FloatConst};
fn foo3<T>(bar: T) -> T where T: Float + FloatConst {
bar + T::pi() // or FloatConst::pi()
}
use num_traits::{Float, FloatConsts};
fn foo4<T>(bar: T) -> T where T: Float + FloatConsts {
bar + T::pi() // or FloatConsts::pi()
}
use num_traits::{Float, FloatConstant};
fn foo5<T>(bar: T) -> T where T: Float + FloatConstant {
bar + T::pi() // or FloatConstant::pi()
}
use num_traits::{Float, FloatConstants};
fn foo6<T>(bar: T) -> T where T: Float + FloatConstants {
bar + T::pi() // or FloatConstants::pi()
} To me personally, singular forms make more sense. Regarding with or without Question 2. Yes, you’re right. Sorry for the confusion. I very much like your idea about all caps. Question 3. Yes, it’s better to keep You’re in charge here, and all the choices are entirely up to you. Please tell me what changes should be made to the pull request. Thank you. |
Somehow I forgot that you can use Sounds like a reasonable consensus: |
I’ve updated the pull request. Thank you. |
Add a trait for floating-point constants The pull request is to address issue #194. In order to keep the library organized, I’ve introduced a new trait for the new functionality. The trait is supposed to closely follows the [`consts`](https://doc.rust-lang.org/std/f64/consts/index.html) module from the standard library. There are at least the following three open questions: 1. What should the name of the trait be? Currently, it’s `Constant`; an alternative is `Consts`. 2. What should the names of the getters be? Currently, they are lower-case versions of the constants defined in the `consts` module. Note that `Float` provides `log2` and `log10`, whereas `LOG_2` and `LOG_10` get translated into `log_2` and `log_10`, respectively. 3. Should `Float` require the new trait? Or should it be left up to the user? Please let me know what you think. Thank you! Regards, Ivan
⚡ Test exempted - status |
…arser Fix rust-num#220 (invalid enum parser)
The pull request is to address issue #194. In order to keep the library organized, I’ve introduced a new trait for the new functionality. The trait is supposed to closely follows the
consts
module from the standard library. There are at least the following three open questions:Constant
; an alternative isConsts
.consts
module. Note thatFloat
provideslog2
andlog10
, whereasLOG_2
andLOG_10
get translated intolog_2
andlog_10
, respectively.Float
require the new trait? Or should it be left up to the user?Please let me know what you think. Thank you!
Regards,
Ivan