Skip to content

Changing rounding mode of "mul" (*) for Fixed to RoundNearest #173

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
kimikage opened this issue Jan 25, 2020 · 1 comment · Fixed by #220
Closed

Changing rounding mode of "mul" (*) for Fixed to RoundNearest #173

kimikage opened this issue Jan 25, 2020 · 1 comment · Fixed by #220

Comments

@kimikage
Copy link
Collaborator

kimikage commented Jan 25, 2020

The current rounding mode of "mul"(*) for Fixed is RoundNearestTiesUp. (The comment "rounding up" is ambiguous, though.) In addition, the implementation with RoundDown is commented out. (The comment "truncation" is also ambiguous, though.)

# with truncation:
#*(x::Fixed{T,f}, y::Fixed{T,f}) = Fixed{T,f}(Base.widemul(x.i,y.i)>>f,0)
# with rounding up:
*(x::Fixed{T,f}, y::Fixed{T,f}) where {T,f} = Fixed{T,f}((Base.widemul(x.i,y.i) + (one(widen(T)) << (f-1)))>>f,0)

However, considering the future addition of checked_mul, I think it would be better to change the rounding mode to the default (i.e. RoundNearest) for consistency.

On the other hand, I would also like to have the interfaces to implementations with other rounding modes, for speed. The problem is that there is no official interface that takes a rounding mode as an argument. The third argument of Base.*() collides with z in x * y * z (Of course, there are no arithmetic operations for RoundingMode, though).

@kimikage
Copy link
Collaborator Author

It might be a temporary option to add a function with a redundant name such as mul_with_rounding.

@kimikage kimikage changed the title Changing rounding mode of mul for Fixed to RoundNearest Changing rounding mode of "mul" (*) for Fixed to RoundNearest Jan 25, 2020
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.

1 participant