-
Notifications
You must be signed in to change notification settings - Fork 23
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 rdiv_with_overflow and fld_with_overflow #109
Conversation
src/FixedPointDecimals.jl
Outdated
C = coefficient(FD{T, f}) | ||
# This case will break the fld call below. This can only happen when f is 0 as y.i | ||
# cannot be -1 otherwise. | ||
if T <: Signed && x.i == typemin(T) && y.i == -1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add the f == 0
check here too? I don't know if julia would be able to infer that away?
if T <: Signed && x.i == typemin(T) && y.i == -1 | |
if T <: Signed && f == 0 && x.i == typemin(T) && y.i == -1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know what I was thinking but that comment was wrong. I guess I was looking at the integral part of y
. y.i
can be -1 when you have e.g. FixedDecimal{Int8,2}(-0.01}
. Apologies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aha, right! 👍
Then we should make sure to test those cases too! Thanks for looking through that!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM thanks! Can you speak to some of my last comments then we can merge? :)
@test rdiv_with_overflow(typemin(FD{Int64,0}), FD{Int64,0}(-1)) == (typemin(FD{Int64,0}), true) | ||
|
||
@test fld_with_overflow(FD{Int8,2}(-1), FD{Int8,2}(0.9)) == (FD{Int8,2}(0.56), true) | ||
@test fld_with_overflow(typemin(FD{Int64,0}), FD{Int64,0}(-1)) == (typemin(FD{Int64,0}), true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
per above, please add a case of non-0 f
:
@test fld_with_overflow(typemin(FD{Int64,2}), FD{Int64,2}(-1)) == (typemin(FD{Int64,2}), true)
or somethign like that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added this for rdiv_with_overflow an equivalent for fld (it doesn't overflow).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops! Right, i meant FD{Int64,2}(-0.01)
-- that is, i want to exercise the overflow case for a non-0 f
.
I think it should be this:
julia> FixedPointDecimals.fld_with_overflow(typemin(FD{Int8,2}), FD{Int8,2}(-0.01))
(FixedDecimal{Int8,2}(-1.28), true)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added the two test cases in PR review comment suggestions :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops :l thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM after the final changes are applied. I'm apply them and merge
No description provided.