-
Notifications
You must be signed in to change notification settings - Fork 33
Empower Fixed
and demotes UFixed.
#35
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
Since writing `x.i` is so short compared to `reinterpret(x)`, it is still all over the codebase. Using `getindex` gives a shorthand `x[]` and makes the code cleaner to read. I was contemplating using `get`, but there is no syntax sugar for that.
This expands the implementation in Fixed to handle more cases and be generally more useful. In the future `UFixed` should be merged in and the special behaviour required by ColorTypes implemented as a new type, based on this implementation.
Next step is to rename |
Fixed
and demote reverts multiplication for UFixed. Fixed
and demotes UFixed.
@@ -40,54 +41,87 @@ export | |||
# Functions | |||
scaledual | |||
|
|||
reinterpret(x::FixedPoint) = x.i | |||
getindex(x::AbstractFixedPoint) = x.i |
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.
This is interesting, but I worry it might give people the wrong idea that there's some kind of tuple or array container inside. So I'm on the fence about it. Care to provide a little explanation?
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.
When going through the codebase I found that reinterpret(x)
and x.i
where both used, thus defeating the point of using reinterpret(x)
, also for me personally reinterpret
makes it harder to read or quickly parse the code. So my main issue with it is that it is to long and it gets in the way. I was thinking about using get(x)
, but it is semantically as problematic as getindex
.
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.
The problem, however, with your solution is that it conflicts with
julia> 5[]
5
julia> 3.2[]
3.2
So anyone who writes code like
function mysum(X)
s = zero(first(X))
for x in X
s += x
end
s
end
will get a very surprising answer from mysum(0xffuf8)
.
x.i
might be used inside FixedPointNumbers
, but I've never seen such usage outside. If this is intended only for internal use, rather than overload an exported function from Base you could define raw
(or something) as an internal function.
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 see your point, I will change it to raw.
On Tue, 3 Nov 2015 18:33 Tim Holy [email protected] wrote:
In src/FixedPointNumbers.jl
#35 (comment)
:@@ -40,54 +41,87 @@ export
# Functions
scaledual-reinterpret(x::FixedPoint) = x.i
+getindex(x::AbstractFixedPoint) = x.iThe problem, however, with your solution is that it conflicts with
julia> 5[]5
julia> 3.2[]3.2
So anyone who writes code like
function mysum(X)
s = zero(first(X))
for x in X
s += x
end
swill get a very surprising answer from mysum(0xffuf8).
x.i might be used inside FixedPointNumbers, but I've never seen such
usage outside. If this is intended only for internal use, rather than
overload an exported function from Base you could define raw (or
something) as an internal function.—
Reply to this email directly or view it on GitHub
https://github.com/JeffBezanson/FixedPointNumbers.jl/pull/35/files#r43728468
.
I'm fine with the name Background: what we now call This analysis does suggest a potential way to unify these numbers successfully. Rather than I don't want unnecessary churn for users (especially since we went through a whole bunch of deprecation warnings very recently!), but in the long run having appropriate names matters. So it's an important discussion. I see at least three options:
I'll add one more comment: one factor worth bearing in mind is that there are presumably very few users (currently) of the general Anyone care to comment? |
(I'd also like to applaud @vchuravy for his continuing efforts here, as well as his interest/willingness to see things done right.) |
@timholy I am happy to be of help, especially since the whole thing started with me not understanding the fine differences between I will rework the PR over the weekend to address your comments. |
Perhaps the reason for the lack of responses here is that it's hard to see the best solution.
Cheers! |
What we need here is a good term for a value from the unit interval. Nothing's coming to mind... |
@timholy what did you mean by this comment:
i ask, because i just spent the day refactoring |
Oh uh. Using generated functions everywhere is not the direction we need to head as a language, but if you make a PR maybe we can figure out another way to do this. If some kind of generated type seems to be necessary for certain classes of problem, then perhaps we can add support for that to the language. Using generated functions to define types is not ideal (and not supported in 0.5). |
Closing for now till I have time to revisit this. |
Supersedes #32.
Instead of doing the big overhaul I decided to do it piecewise. (If anything is controversial we can also use 0a8e222 independently to close #34).
I adopted most changes from #32 and the next step would be to rename
UFixed
and deprecate its usage to freeUFixed
to be used as unsigned fixed-point and to rework theUFixed
implementation to properly reflect its normalized nature.