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

Clean up some trait impls in core::num. #15900

Merged
merged 1 commit into from
Jul 23, 2014
Merged

Conversation

tbu-
Copy link
Contributor

@tbu- tbu- commented Jul 22, 2014

This removes the special casing for floats where it was not necessary, as
-0.0 == 0.0.


#[inline]
fn is_zero(&self) -> bool { *self == $v || *self == -$v }
fn is_zero(&self) -> bool { *self == Zero::zero() }
Copy link
Contributor

Choose a reason for hiding this comment

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

If you're going to use Zero::zero() here you may as well make this a default method implementation on the trait.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tried that, but it doesn't work as Zero doesn't need Eq or PartialEq.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, fair enough. Well, in that case, is there any particular reason to use Zero::zero() here instead of just using $v as was previously done? After optimization it should ultimately generate the same code, but it just seems simpler (to me as a reader of the code) to continue using $v.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Dunno, if this wasn't in a macro I'd say: Keep the magic constant in one place, so you can change it easily – it's not so bad in a macro I guess. Want me to change it back?

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree, if it wasn't a macro I'd use Zero::zero(). But it is a macro, which means the magic constant stays in one location in the source code.

I'd be happier if you changed it back.

This removes the special casing for `float`s where it was not necessary, as
`-0.0 == 0.0`.
@tbu-
Copy link
Contributor Author

tbu- commented Jul 22, 2014

@kballard Fixed it.

bors added a commit that referenced this pull request Jul 23, 2014
This removes the special casing for `float`s where it was not necessary, as
`-0.0 == 0.0`.
@bors bors closed this Jul 23, 2014
@bors bors merged commit 737d92e into rust-lang:master Jul 23, 2014
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 16, 2023
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.

3 participants