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

make flipsign(typemin(T), -1) == typemin(T) consistently #22016

Merged
merged 1 commit into from
Jun 2, 2017

Conversation

rfourquet
Copy link
Member

@rfourquet rfourquet commented May 22, 2017

Cf. #21984 (comment) where the discussion started.
This makes flipsign(x, y) always (hopefully) equal to y < 0 ? +x : -x.
Before: flipsign(typemin(Int8), -1) was an InexactError() but copysign(typemin(Int8), -1) == -128, and -typemin(Int8) == -128.

This PR also

  • makes those methods typestable on Bool by adding a + which is a no-op in most cases.
  • add a special case when the second argument is Unsigned, but I'm not sure this is really faster.

@ararslan ararslan added the maths Mathematical functions label May 22, 2017
@rfourquet
Copy link
Member Author

Ok to merge?

@StefanKarpinski
Copy link
Member

LGTM – go for it.

Also, make `flipsign(::Bool, y)` typestable, and add
`flipsign(x, Unsigned) = +x`.
@rfourquet
Copy link
Member Author

Thanks @StefanKarpinski for helping with my PRs!

@rfourquet rfourquet deleted the rf/flipsign branch June 2, 2017 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maths Mathematical functions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants