Closed
Description
As mentioned in #211 (comment), the rem
for Fixed
has problems.
FixedPointNumbers.jl/src/fixed.jl
Line 109 in 735b7f9
I plan to specialize the multiplication for
Fixed
after the merging PR #213. As part of the specialization, I will improve the rem
for Fixed
, but since it is not the main topic of the specialization, I opened a separate issue for rem
.
Speed performance
Simply put, rem
for Fixed
is too slow.
julia> x_f32 = rand(Float32, 1000, 1000);
julia> @btime $x_f32 .% Q0f7;
8.012 ms (2 allocations: 976.70 KiB)
julia> @btime $x_f32 .% N0f8;
123.300 μs (2 allocations: 976.70 KiB)
Throwing errors
Though this is one of the causes of the slowdown, the rem
can throw an error.
julia> 2.0^63 % Q0f7 # Due to `Integer()`
ERROR: InexactError: Int64(9.223372036854776e18)
The rem
for Normed
prioritizes the speed and allows for inaccurate values to be returned in the overflow.
Unnecessary type conversion
We need the specialized method.
julia> typemax(Q0f63) % Q0f63
ERROR: ArgumentError: Fixed{Int64,63} is a 64-bit type representing 0 values from -1.0 to 1.0; cannot represent 1
Metadata
Metadata
Assignees
Labels
No labels