Add checked, wrapping and saturating arithmetic for div/cld/fld - #226
Merged
Conversation
The default arithmetic for `div` is still checked arithmetic. This changes the error type for overflow from `DivideError` to `OverflowError`. This also adds the support for `cld` and 3-arg `div`.
This was referenced Sep 3, 2020
Codecov Report
@@ Coverage Diff @@
## master #226 +/- ##
==========================================
+ Coverage 95.19% 95.42% +0.22%
==========================================
Files 6 6
Lines 645 677 +32
==========================================
+ Hits 614 646 +32
Misses 31 31
Continue to review full report at Codecov.
|
Collaborator
Author
BenchmarkSee #222 (comment) for detail of variables. for op in (div, fld)
@btime $op.($z_q0f7 , $w_q0f7 );
@btime $op.($z_q0f15, $w_q0f15);
@btime $op.($z_q3f4 , $w_q3f4 );
@btime $op.($z_q3f12, $w_q3f12);
@btime $op.($z_n0f8 , $w_n0f8 );
@btime $op.($z_n0f16, $w_n0f16);
@btime $op.($z_n4f4 , $w_n4f4 );
@btime $op.($z_n4f12, $w_n4f12);
end@btime wrapping_div.($x_q0f7 , $y_q0f7 );
@btime wrapping_fld.($x_q0f7 , $y_q0f7 );
@btime wrapping_cld.($x_q0f7 , $y_q0f7 );
@btime wrapping_div.($x_q0f15, $y_q0f15);
@btime wrapping_div.($x_q3f4 , $y_q3f4 );
@btime wrapping_div.($x_q3f12, $y_q3f12);
@btime wrapping_div.($x_n0f8 , $y_n0f8 );
@btime wrapping_fld.($x_n0f8 , $y_n0f8 );
@btime wrapping_cld.($x_n0f8 , $y_n0f8 );
@btime wrapping_div.($x_n0f16, $y_n0f16);
@btime wrapping_div.($x_n4f4 , $y_n4f4 );
@btime wrapping_div.($x_n4f12, $y_n4f12);
@btime saturating_div.($x_q0f7 , $y_q0f7 );
@btime saturating_fld.($x_q0f7 , $y_q0f7 );
@btime saturating_cld.($x_q0f7 , $y_q0f7 );
@btime saturating_div.($x_q0f15, $y_q0f15);
@btime saturating_div.($x_q3f4 , $y_q3f4 );
@btime saturating_div.($x_q3f12, $y_q3f12);
@btime saturating_div.($x_n0f8 , $y_n0f8 );
@btime saturating_fld.($x_n0f8 , $y_n0f8 );
@btime saturating_cld.($x_n0f8 , $y_n0f8 );
@btime saturating_div.($x_n0f16, $y_n0f16);
@btime saturating_div.($x_n4f4 , $y_n4f4 );
@btime saturating_div.($x_n4f12, $y_n4f12);
|
Fixed |
before | after | Normed |
before | after | |
|---|---|---|---|---|---|---|
(z_q0f7 , w_q0f7 ) |
2.019 ms | 1.541 ms | (z_n0f8 , w_n0f8 ) |
1.793 ms | 1.321 ms | |
(z_q0f15, w_q0f15) |
3.085 ms | 2.173 ms | (z_n0f16, w_n0f16) |
2.427 ms | 1.932 ms | |
(z_q3f4 , w_q3f4 ) |
2.019 ms | 1.544 ms | (z_n4f4 , w_n4f4 ) |
1.791 ms | 1.291 ms | |
(z_q3f12, w_q3f12) |
3.320 ms | 2.428 ms | (z_n4f12, w_n4f12) |
2.423 ms | 2.228 ms |
fld (checked_fld)
Fixed |
before | after | Normed |
before | after | |
|---|---|---|---|---|---|---|
(z_q0f7 , w_q0f7 ) |
3.363 ms | 1.540 ms | (z_n0f8 , w_n0f8 ) |
1.793 ms | 1.327 ms | |
(z_q0f15, w_q0f15) |
3.989 ms | 2.194 ms | (z_n0f16, w_n0f16) |
2.431 ms | 1.967 ms | |
(z_q3f4 , w_q3f4 ) |
3.356 ms | 1.544 ms | (z_n4f4 , w_n4f4 ) |
1.795 ms | 1.312 ms | |
(z_q3f12, w_q3f12) |
4.030 ms | 2.227 ms | (z_n4f12, w_n4f12) |
2.434 ms | 2.164 ms |
wrapping_*
Fixed |
Normed |
||||
|---|---|---|---|---|---|
wrapping_div. |
(x_q0f7 , y_q0f7 ) |
496.4 μs | (x_n0f8 , y_n0f8 ) |
323.1 μs | |
wrapping_fld. |
(x_q0f7 , y_q0f7 ) |
496.1 μs | (x_n0f8 , y_n0f8 ) |
309.3 μs | |
wrapping_cld. |
(x_q0f7 , y_q0f7 ) |
496.6 μs | (x_n0f8 , y_n0f8 ) |
309.0 μs | |
wrapping_div. |
(x_q0f15, y_q0f15) |
1.054 ms | (x_n0f16, y_n0f16) |
909.5 μs | |
wrapping_div. |
(x_q3f4 , y_q3f4 ) |
496.4 μs | (x_n4f4 , y_n4f4 ) |
309.9 μs | |
wrapping_div. |
(x_q3f12, y_q3f12) |
1.105 ms | (x_n4f12, y_n4f12) |
869.3 μs |
saturating_*
Fixed |
Normed |
||||
|---|---|---|---|---|---|
saturating_div. |
(x_q0f7 , y_q0f7 ) |
319.8 μs | (x_n0f8 , y_n0f8 ) |
489.3 μs | |
saturating_fld. |
(x_q0f7 , y_q0f7 ) |
319.7 μs | (x_n0f8 , y_n0f8 ) |
485.4 μs | |
saturating_cld. |
(x_q0f7 , y_q0f7 ) |
320.2 μs | (x_n0f8 , y_n0f8 ) |
485.7 μs | |
saturating_div. |
(x_q0f15, y_q0f15) |
936.1 μs | (x_n0f16, y_n0f16) |
1.014 ms | |
saturating_div. |
(x_q3f4 , y_q3f4 ) |
319.8 μs | (x_n4f4 , y_n4f4 ) |
485.5 μs | |
saturating_div. |
(x_q3f12, y_q3f12) |
973.9 μs | (x_n4f12, y_n4f12) |
967.2 μs |
Collaborator
Author
|
I'm going to move on to the implementation of Probably most people are not interested in the division as I'm not interested in it.:joy: |
kimikage
added a commit
to kimikage/FixedPointNumbers.jl
that referenced
this pull request
May 1, 2024
…or div/cld/fld (JuliaMath#226)" The wrapping and saturating `div`/`cld`/`fld` are not backported. The default arithmetic for `div` is still checked arithmetic. This changes the error type for overflow from `DivideError` to `OverflowError`. This also adds the support for `cld` and 3-arg `div`.
kimikage
added a commit
to kimikage/FixedPointNumbers.jl
that referenced
this pull request
May 1, 2024
…or div/cld/fld (JuliaMath#226)" The wrapping and saturating `div`/`cld`/`fld` are not backported. The default arithmetic for `div` is still checked arithmetic. This changes the error type for overflow from `DivideError` to `OverflowError`. This also adds the support for `cld` and 3-arg `div`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The default arithmetic for
divis still checked arithmetic.This changes the error type for overflow from
DivideErrortoOverflowError.This also adds the support for
cldand 3-argdiv.