-
Notifications
You must be signed in to change notification settings - Fork 33
Add rounding functions for Fixed
(Fixes #153)
#158
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
Conversation
This also simplifies the test for rounding functions.
Let's merge this before #163 |
The functions support `Fixed{Int8,8}` and so on, for now.
Though I merged PR #159, this PR supports |
function floor(x::Fixed{T,f}) where {T, f} | ||
f == bitwidth(T) && x.i < 0 && throw_converterror(Fixed{T,f}, -1) # TODO: remove this line | ||
Fixed{T,f}(x.i & intmask(x), 0) | ||
end |
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 would like to confirm just in case, your implementation is much more complex.
FixedPointNumbers.jl/src/fixed.jl
Lines 92 to 96 in ebc5eff
function round(x::Fixed{T,f}, ::RoundingMode{:Down}) where {T,f} | |
mask = abs(rawminusone(Fixed{T,f}) + oneunit(T)) | |
xraw = reinterpret(x) | |
return Fixed{T,f}((xraw & ~mask) + (signbit(xraw) & (xraw & mask) != 0 ? rawminusone(Fixed{T,f}) : zero(xraw)), 0) | |
end |
Am I overlooking something?
(I'm sleepy now, so the decision for merging is pending. Feel free to merge this.:sleepy:)
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.
No, you're absolutely right, the simpler one looks correct. 👍
This is a part of #151 and fixes #153.
succeeding PRs: this ->
isinteger
(#120) ->rem
(#150) ->Integer
(#154) ->Rational
(#157)Edit:
Let's decide #159 first.Done.