Commonize code between Fixed and Normed#151
Conversation
a65286c to
a2e3323
Compare
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.
| 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.
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.
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. fromInexactErrortoArgumentError.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