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

Add rdiv_with_overflow and fld_with_overflow #109

Merged
merged 22 commits into from
Feb 17, 2025
Merged

Conversation

mbarbar
Copy link
Contributor

@mbarbar mbarbar commented Feb 6, 2025

No description provided.

@mbarbar mbarbar requested a review from NHDaly February 12, 2025 04:46
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
Copy link
Member

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?

Suggested change
if T <: Signed && x.i == typemin(T) && y.i == -1
if T <: Signed && f == 0 && x.i == typemin(T) && y.i == -1

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 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.

Copy link
Member

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!

Copy link
Member

@NHDaly NHDaly left a 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)
Copy link
Member

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

Copy link
Contributor Author

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).

Copy link
Member

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)

Copy link
Member

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 :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whoops :l thanks

@mbarbar mbarbar requested a review from NHDaly February 15, 2025 12:30
Copy link
Member

@NHDaly NHDaly left a 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

@NHDaly NHDaly merged commit 515934e into JuliaMath:master Feb 17, 2025
8 of 12 checks passed
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.

2 participants