Hi all,
I am one of the committers of FixedPointNumbers.jl and we are currently working on the next version, v0.9.0, to be released.
This is not directly related to the visualization, but I’m writing this in the visualization category because the JuliaImages and JuliaPlots communities will be most affected by the decision of this issue.
TL;DR
Can you accept that the FixedPoint
computation suddenly slows down or that the existing code throws an error?
Or, would you prefer to ignore the overflow and get faster speed?
Or, do you prefer to maintain the status quo as much as possible?
Background
As you know, in Julia, the 8-bit N0f8
type defined in FixedPointNumbers
is often used to represent 8-bit gray or 24-bit RGB color. Since types like N0f8
easily cause overflow in the addition and subtraction, the issue with overflow has long been discussed. @tim.holy summarized the proposals discussed in the past year.
In the meantime, I had been frustrated with the implementation of arithmetic operations in FixedPointNumbers
. As an extreme example, the multiplication between N0f8
numbers had room to be 25x faster.
So, I decided to improve the implementation of arithmetic in the next v0.9.0. Also, in the improvement, I decided to support three types of arithmetic (i.e. wrapping, saturating and checked) as a measure to mitigate the overflow problem. And then, the implementations are almost complete (cf. https://github.com/JuliaMath/FixedPointNumbers.jl/issues/41#issuecomment-674682747).
Thus, with FixedPointNumbers#master
, you can try the following code.
julia> using FixedPointNumbers, Base.Checked
julia> 0.8N0f8 + 0.8N0f8
0.596N0f8
julia> wrapping_add(0.8N0f8, 0.8N0f8)
0.596N0f8
julia> saturating_add(0.8N0f8, 0.8N0f8)
1.0N0f8
julia> checked_add(0.8N0f8, 0.8N0f8)
ERROR: OverflowError: 0.8N0f8 + 0.8N0f8 overflowed for type N0f8
Of course, it’s annoying for the end-user or the developer of a high-level package to specify the arithmetic for every operation. Therefore, I believe that we need some kind of tools, and one of those tools is CheckedArithmetic.jl made by @tim.holy.
julia> using CheckedArithmetic
julia> @checked 0.8N0f8 + 0.8N0f8 # `@checked` replaces `+` with `checked_add`
ERROR: OverflowError: 0.8N0f8 + 0.8N0f8 overflowed for type N0f8
Although there are still some issues in using CheckedArithmetic
with FixedPointNumbers
, I’ll be working on improving CheckedArithmetic
as well.
These new arithmetic implementations do not essentially solve the overflow problems and we still need to discuss them. However, I believe that releasing the new arithmetic implementations is a step forward.
Discussion
In the run-up to the release, we have to make at least two decisions.
API definitions (or release cycle)
One is which modules should define the interfaces of wrapping_*
and saturating_*
and whether they should be exported by FixedPointNumbers
.
This may be not a important decision for users. However, I’m thinking of putting those interface definitions in CheckedArithmetic
(CheckedArithmeticCore
). In that case, the release of v0.9.0 will take a little longer. If people want to use the latest version sooner, we’ll release them as private APIs first, and then will change the owner of the APIs after v0.9.0 is released. In order to be actually available, v0.9.0 has to be supported by downstream packages, such as ColorTypes.jl, and that will still take some time, though.
Default arithmetic
The other thing, and this is an important decision, is what the default arithmetic should be, e.g. what the result of 0.8N0f8 + 0.8N0f8
should be.
I’m not going to vote on this, but I will describe the options individually to make it easier to reply.