-
Notifications
You must be signed in to change notification settings - Fork 33
Commonize code between Fixed
and Normed
#151
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
a65286c
to
a2e3323
Compare
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.
src/normed.jl
Outdated
xu = reinterpret(Unsigned, x) | ||
k = Int(xu >> significand_bits(Tf)) | ||
k == 0 && return zero(N) # neglect subnormal numbers | ||
significand = xu | (one(xu) << significand_bits(Tf)) |
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.
significand = xu | (one(xu) << significand_bits(Tf)) | |
significand = xu | (oneunit(xu) << significand_bits(Tf)) |
(I failed to notice this earlier.)
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.
Do we need to worry about the difference between one
and oneunit
for types without dimensions?
Anyway, I changed one
to oneunit
for future consistency.
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.
Not so far, but in cases where you mean "1 of the given type" then oneunit
is appropriate, no matter whether it differs from one
.
one
is a little weird because it could pretty much be defined as the constant 1
.
FixedPointNumbers.jl/src/FixedPointNumbers.jl Lines 34 to 37 in 7ad0f0c
FixedPointNumbers.jl/src/normed.jl Lines 254 to 256 in 7ad0f0c
They don't seem to differ in essence. |
This changes the exception type of `one(Q0f7)` etc. from `InexactError` to `ArgumentError`.
Although `minmax` has been available, but this specializes it.
I added tests for Edit: I have confirmed that this has passed in my forked repository. |
the minimum required FixedPointNumbers is 0.8.0 since it includes the bswap code from JuliaMath/FixedPointNumbers.jl#151
This PR is the first part of #139.
I am very sorry about a conflict with #143, but in the long-term, I think this PR will help enhance the functions (e.g. checked arithmetic).
Because there are many changes, it is recommended that you track changes on a per-commit basis.
This PR includes a minor breaking change, i.e., this change the exception type of
one(Q0f7)
etc. fromInexactError
toArgumentError
.I'm ready to fix
isinteger
(issue #120, PR #123) after the merging this PR. And then, I'll fix the issue #150.Edit:
Rescheduling: this -> issue #153 ->
isinteger
->rem
-> issue #157