Skip to content

Define ::Integer * ::FixedPoint? #78

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

Closed
TotalVerb opened this issue Feb 23, 2017 · 2 comments · Fixed by #207
Closed

Define ::Integer * ::FixedPoint? #78

TotalVerb opened this issue Feb 23, 2017 · 2 comments · Fixed by #207

Comments

@TotalVerb
Copy link

julia> 2 * 0.5Q1f14
ERROR: InexactError()
Stacktrace:
 [1] convert at /home/fengyang/.julia/v0.6/FixedPointNumbers/src/fixed.jl:42 [inlined]
 [2] promote at ./promotion.jl:174 [inlined]
 [3] *(::Int64, ::FixedPointNumbers.Fixed{Int16,14}) at ./promotion.jl:247

This is happening because 2 is not representable in Q1f14, even though the result 1 would be. I think it is avoidable by specializing ::Integer * ::FixedPoint (and ::FixedPoint * ::Integer?) directly, but I don't have much experience with this. If this is the right thing to do, I'll make a PR.

@vchuravy
Copy link
Collaborator

Yes this is due to our promote rules... I think implementing ::Integer * ::FixedPoint is fine, but we need to think about whether we want to check for overflow.

@kimikage
Copy link
Collaborator

kimikage commented Jul 7, 2020

I misunderstood this issue. This is a problem with promotion rules only for Fixed, not for Normed. Since the birth of Normed (formerly UFixed), i.e. PR #2, it has been promoted to Float32/Float64.

I thought the checked_mul could avoid unnecessary errors, but that would lead to further inconsistencies. 😕

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 a pull request may close this issue.

3 participants