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

Implement CoreFloat trait #32

Merged
merged 5 commits into from Feb 7, 2018
Merged

Implement CoreFloat trait #32

merged 5 commits into from Feb 7, 2018

Conversation

vks
Copy link
Contributor

@vks vks commented Feb 2, 2018

This is a subset of the Float trait, but works with no_std.
Some code was simplified by using CoreFloat.

This is a subset of the `Float` trait, but works with `no_std`.
Some code was simplified by using `CoreFloat`.
Copy link
Member

@cuviper cuviper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you mention this as an alternative in the Features section of README.md?

One bikeshed possibility is FloatCore, to be a little more consistent with FloatConst, but I can go either way. Choose whichever name you prefer. :)

src/float.rs Outdated
pub trait CoreFloat: Num + Neg<Output = Self> + PartialOrd + Copy {
/// Returns positive infinity.
#[inline]
fn infinity() -> Self;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#[inline] has no effect without a function body -- see rust-lang/rust#47475. That should be moved to the actual implementations.

src/lib.rs Outdated
@@ -26,7 +26,7 @@ use core::fmt;
pub use bounds::Bounded;
#[cfg(feature = "std")]
pub use float::Float;
pub use float::FloatConst;
pub use float::{CoreFloat, FloatConst};
// pub use real::Real; // NOTE: Don't do this, it breaks `use num_traits::*;`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we may have the same concern as Real did here. If someone does use num_traits::*, then the common methods between Float and CoreFloat may be ambiguous. Would you mind if we didn't re-export this in the root?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure supporting wildcard imports is worthwhile. If you want to make sure not to break them, you can't add any new functions or types. However, in this case I guess it is easy enough to avoid that problem.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure either. I guess a wildcard making us self-conflicting is a worse than having a conflict with some unrelated crate though.

@cuviper cuviper modified the milestone: num-traits-0.2 Feb 2, 2018
@vks
Copy link
Contributor Author

vks commented Feb 7, 2018

I think I addressed all your comments.

@cuviper
Copy link
Member

cuviper commented Feb 7, 2018

Looks great, thanks!

bors r+

bors bot added a commit that referenced this pull request Feb 7, 2018
32: Implement CoreFloat trait r=cuviper a=vks

This is a subset of the `Float` trait, but works with `no_std`.
Some code was simplified by using `CoreFloat`.
@bors
Copy link
Contributor

bors bot commented Feb 7, 2018

Build succeeded

@bors bors bot merged commit 52bc8eb into rust-num:master Feb 7, 2018
@cuviper
Copy link
Member

cuviper commented Feb 7, 2018

@vks I just noticed that this doesn't require NumCast like Float does. Was that intentional?

@vks
Copy link
Contributor Author

vks commented Feb 8, 2018 via email

@cuviper
Copy link
Member

cuviper commented Feb 8, 2018 via email

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

Successfully merging this pull request may close these issues.

None yet

2 participants