-
Notifications
You must be signed in to change notification settings - Fork 32
Fix div and friends #47
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
|
I am not on a computer right now so I couldn't just test this :) Was the problem here the return type of the |
1b280ec to
415a58c
Compare
|
This is what happens on master: julia> using FixedPointNumbers
INFO: Recompiling stale cache file /home/tim/.julia/lib/v0.5/FixedPointNumbers.ji for module FixedPointNumbers.
julia> x = 16uf8
UFixed{UInt8,8}(0.063)
julia> y = 2uf8
UFixed{UInt8,8}(0.008)
julia> div(x, y)
UFixed{UInt8,8}(0.031)
julia> div(Float32(x), Float32(y))
8.0f0
julia> r = 1uf8:1uf8:10uf8
UFixed{UInt8,8}(0.004):UFixed{UInt8,8}(0.004):UFixed{UInt8,8}(0.039)
julia> length(r)
------ InexactError -------------------- Stacktrace (most recent call last)
[1] — length(::StepRange{FixedPointNumbers.UFixed{UInt8,8},FixedPointNumbers.UFixed{UInt8,8}}) at range.jl:364
[2] — unsafe_length(::StepRange{FixedPointNumbers.UFixed{UInt8,8},FixedPointNumbers.UFixed{UInt8,8}}) at range.jl:361
InexactError()None of those problems happen with this branch. |
|
Hm I see. I am still trying to wrap my head around this. Isn't the problem Can I also note that the printing of On Sun, 11 Sep 2016, 21:14 Tim Holy, [email protected] wrote:
|
| for f in (:div, :fld, :rem, :mod, :mod1, :rem1, :fld1, :min, :max) | ||
| for f in (:div, :fld, :fld1) | ||
| @eval begin | ||
| $f{T<:UFixed}(x::T, y::T) = $f(reinterpret(x),reinterpret(y)) |
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 what confuses me. The result type here is now an unsigned integer.
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.
Are you arguing we should throw an InexactError?
|
Yes, it's not representable, but in general you expect it not to be. The definition of I'm not sure I follow what's broken about the printing/conversion to Float32: julia> x = 2uf8
UFixed{UInt8,8}(0.008)
julia> Float32(x)
0.007843138f0(except I'm bummed about how verbose the printing is, I thought we'd fixed that) |
|
Ahhh, I am too tired. You are of course right.
Thanks for explaining. LGTM from my side. |
Gracious me, coding by copy/paste does have its downsides.
This one was my fault from back in 2014, I believe. Amazing it's not been noticed before.