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

sign((-1)//typemin(Int)) != sign(typemin(Int)//(-1)) #32443

Closed
JeffreySarnoff opened this issue Jun 27, 2019 · 4 comments · Fixed by #51085
Closed

sign((-1)//typemin(Int)) != sign(typemin(Int)//(-1)) #32443

JeffreySarnoff opened this issue Jun 27, 2019 · 4 comments · Fixed by #51085
Labels
domain:rationals The Rational type and values thereof

Comments

@JeffreySarnoff
Copy link
Contributor

JeffreySarnoff commented Jun 27, 2019

julia> sign(typemin(Int)//(-1))
-1//1
julia> sign((-1)//typemin(Int))
1//1

and also for the other Signed bitstypes and also for signbit.

@JeffreySarnoff JeffreySarnoff changed the title sign((-1)//typemin(Int)) != sign(typemin(Int)//(-1)) sign((-1)//typemin(Int)) != sign(typemin(Int)//(-1)) Jun 27, 2019
@Moelf
Copy link
Sponsor Contributor

Moelf commented Jun 28, 2019

problems seems to be:

julia> ((-1)//typemin(Int)).num
1

julia> (typemin(Int)//(-1)).num
-9223372036854775808

@musm
Copy link
Contributor

musm commented Jun 28, 2019

This is because
typemin(Int) == -typemin(Int) # true

@JeffreySarnoff
Copy link
Contributor Author

one(T)//typemin(T), typemin(T)//one(T) are legit
(-one(T))//typemin(T), typemin(T)//(-one(T)) are not because there is no value in T == |typemin(T)|
we trap Rational overflow rather than autowiden, yet this is not trapped

@JeffBezanson JeffBezanson added the domain:rationals The Rational type and values thereof label Jul 1, 2019
@Liozou
Copy link
Member

Liozou commented Apr 12, 2020

Fixed by #32572?

oscardssmith pushed a commit that referenced this issue Oct 21, 2023
Fixes #32443

Currently `typemin(Int)//(-1) == typemin(Int)//(1)`, ignoring an
overflow.

As noted by @JeffreySarnoff in
[#32443](#32443 (comment))
This should throw an error instead of silently overflowing.

To fix this I am using `checked_neg` instead of `-` in the Rational
constructor.

With this PR `(-one(T))//typemin(T)` will now also throw an
`OverflowError` instead of an `ArgumentError`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:rationals The Rational type and values thereof
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants