-
Notifications
You must be signed in to change notification settings - Fork 34
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
Add checked arithmetic for /
#222
Conversation
1e1bcab
to
b04f088
Compare
c8c3fd4
to
416e425
Compare
Codecov Report
@@ Coverage Diff @@
## master #222 +/- ##
==========================================
+ Coverage 91.46% 91.58% +0.11%
==========================================
Files 6 6
Lines 574 582 +8
==========================================
+ Hits 525 533 +8
Misses 49 49
Continue to review full report at Codecov.
|
Benchmarkx_q0f7 = rand(Q0f7, 1000, 1000); y_q0f7 = rand(Q0f7, 1000, 1000);
x_q0f15 = rand(Q0f15, 1000, 1000); y_q0f15 = rand(Q0f15, 1000, 1000);
x_q3f4 = rand(Q3f4, 1000, 1000); y_q3f4 = rand(Q3f4, 1000, 1000);
x_q3f12 = rand(Q3f12, 1000, 1000); y_q3f12 = rand(Q3f12, 1000, 1000);
x_n0f8 = rand(N0f8, 1000, 1000); y_n0f8 = rand(N0f8, 1000, 1000);
x_n0f16 = rand(N0f16, 1000, 1000); y_n0f16 = rand(N0f16, 1000, 1000);
x_n4f4 = rand(N4f4, 1000, 1000); y_n4f4 = rand(N4f4, 1000, 1000);
x_n4f12 = rand(N4f12, 1000, 1000); y_n4f12 = rand(N4f12, 1000, 1000);
non_zero(x) = x === zero(x) ? eps(x) : x;
z(x::X) where X = clamp(x * 0.5 * rand(X), X);
w_q0f7 = non_zero.(y_q0f7); z_q0f7 = z.(w_q0f7);
w_q0f15 = non_zero.(y_q0f15); z_q0f15 = z.(w_q0f15);
w_q3f4 = non_zero.(y_q3f4); z_q3f4 = z.(w_q3f4);
w_q3f12 = non_zero.(y_q3f12); z_q3f12 = z.(w_q3f12);
w_n0f8 = non_zero.(y_n0f8); z_n0f8 = z.(w_n0f8);
w_n0f16 = non_zero.(y_n0f16); z_n0f16 = z.(w_n0f16);
w_n4f4 = non_zero.(y_n4f4); z_n4f4 = z.(w_n4f4);
w_n4f12 = non_zero.(y_n4f12); z_n4f12 = z.(w_n4f12);
@btime $z_q0f7 ./ $w_q0f7;
@btime $z_q0f15 ./ $w_q0f15;
@btime $z_q3f4 ./ $w_q3f4;
@btime $z_q3f12 ./ $w_q3f12;
@btime $z_n0f8 ./ $w_n0f8;
@btime $z_n0f16 ./ $w_n0f16;
@btime $z_n4f4 ./ $w_n4f4;
@btime $z_n4f12 ./ $w_n4f12; @btime wrapping_fdiv.($x_q0f7 , $y_q0f7 );
@btime wrapping_fdiv.($x_q0f15, $y_q0f15);
@btime wrapping_fdiv.($x_q3f4 , $y_q3f4 );
@btime wrapping_fdiv.($x_q3f12, $y_q3f12);
@btime wrapping_fdiv.($x_n0f8 , $y_n0f8 );
@btime wrapping_fdiv.($x_n0f16, $y_n0f16);
@btime wrapping_fdiv.($x_n4f4 , $y_n4f4 );
@btime wrapping_fdiv.($x_n4f12, $y_n4f12);
@btime saturating_fdiv.($x_q0f7 , $y_q0f7 );
@btime saturating_fdiv.($x_q0f15, $y_q0f15);
@btime saturating_fdiv.($x_q3f4 , $y_q3f4 );
@btime saturating_fdiv.($x_q3f12, $y_q3f12);
@btime saturating_fdiv.($x_n0f8 , $y_n0f8 );
@btime saturating_fdiv.($x_n0f16, $y_n0f16);
@btime saturating_fdiv.($x_n4f4 , $y_n4f4 );
@btime saturating_fdiv.($x_n4f12, $y_n4f12); julia> versioninfo()
Julia Version 1.5.1
Commit 697e782ab8 (2020-08-25 20:08 UTC)
Platform Info:
OS: Windows (x86_64-w64-mingw32)
CPU: Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-9.0.1 (ORCJIT, skylake)
|
b8f066a
to
a82ceb4
Compare
JuliaLang/julia #37085 was merged. ("Normed{UInt128,100}"-->"Normed{UInt128, 100}") |
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.
Interesting that we've had checked here a long time and I no longer remembered that...I can't remember the last time I divided FixedPoints, but I suspect it has come up.
FYI, the julia> 10N4f12 * 10N4f12 # v0.8.4
ERROR: ArgumentError: Normed{UInt16,12} is a 16-bit type representing 65536 values from 0.0 to 16.0037; cannot represent 100.0
julia> 10N4f12 * 10N4f12 # PR #213 (checked arithmetic for `Normed`)
ERROR: OverflowError: 10.0N4f12 * 10.0N4f12 overflowed for type N4f12
julia> 10Q4f11 * 10Q4f11 # PR #220 (wrapping arithmetic for `Fixed`)
4.0Q4f11 I will soon be asking for feedback on the default arithmetic in v0.9 and the state of arithmetic in v0.10 and later in the Discourse. |
Yeah, I think with multiplication I always convert to |
This also changes the implementation of `/` for `Fixed`. `/` (`checked_fdiv`) throws `DivideError` for division by zero and `OverflowError` for overflow.
I ran |
This also changes the implementation of
/
forFixed
. The new/
also checks for overflow./
(checked_fdiv
) throwsDivideError
for division by zero andOverflowError
for overflow.