You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Perhaps the following is more accurate than the current implementation, and less accurate than PR #131.
function Base.rem(x::Float32, ::Type{T}) where {f, T <:Normed{UInt32,f}}
f <=24&&returnreinterpret(T, unsafe_trunc(UInt32, round(rawone(T)*x)))
r =unsafe_trunc(UInt32, round(Int32, x *Float32(0x1p24)))
reinterpret(T, r <<UInt8(f -24) - r >>0x18)
end
Definitely worth fixing. Though I can't imagine why the docs use N0f32, from a perceptual standpoint that's serious overkill. I posted a query about the reasons for that choice in JuliaGraphics/Colors.jl#324
functionrem(x::Float32, ::Type{T}) where {f, T <:Normed{UInt32,f}}
f <=24&&returnreinterpret(T, _unsafe_trunc(UInt32, round(rawone(T) * x)))
r =_unsafe_trunc(UInt32, round(x *@f32(0x1p24)))
reinterpret(T, r <<UInt8(f -24) -unsigned(signed(r) >>0x18))
endfunctionrem(x::Float64, ::Type{T}) where {f, T <:Normed{UInt64,f}}
f <=53&&returnreinterpret(T, _unsafe_trunc(UInt64, round(rawone(T) * x)))
r =_unsafe_trunc(UInt64, round(x *0x1p53))
reinterpret(T, r <<UInt8(f -53) -unsigned(signed(r) >>0x35))
end
However, similar problem remains due to the overflow instead of rounding error.
Activity
kimikage commentedon Dec 15, 2019
Perhaps the following is more accurate than the current implementation, and less accurate than PR #131.
kimikage commentedon Dec 16, 2019
BTW, I reported this issue because I noticed that the documents of Colors.jl include the example with
N0f32.JuliaGraphics/Colors.jl#324
http://juliagraphics.github.io/Colors.jl/latest/namedcolors/
I think it would be easier to fix the bug than add a note to the document.
timholy commentedon Dec 17, 2019
Definitely worth fixing. Though I can't imagine why the docs use
N0f32, from a perceptual standpoint that's serious overkill. I posted a query about the reasons for that choice in JuliaGraphics/Colors.jl#324kimikage commentedon Dec 18, 2019
minor adjustment:
However, similar problem remains due to the overflow instead of rounding error.
Since
% Tis often used in constructors (cf.ColorTypes.jl), the following benchmark is not so practical.Improve accuracy of `rem` with `Normed` types (e.g. `::Float32 % N0f3…