Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
open-runtime-module-library
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Noxim
open-runtime-module-library
Commits
2e054ce9
Unverified
Commit
2e054ce9
authored
5 years ago
by
Shaopeng Wang
Committed by
GitHub
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Fixed128: fix dividend zero checked_div panic. (#125)
parent
714efa56
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
utilities/src/fixed_128.rs
+12
-0
12 additions, 0 deletions
utilities/src/fixed_128.rs
with
12 additions
and
0 deletions
utilities/src/fixed_128.rs
+
12
−
0
View file @
2e054ce9
...
...
@@ -92,6 +92,10 @@ impl Fixed128 {
if
rhs
.0
.signum
()
==
0
{
return
None
;
}
if
self
.0
==
0
{
return
Some
(
*
self
);
}
let
signum
=
self
.0
.signum
()
/
rhs
.0
.signum
();
let
mut
lhs
:
i128
=
self
.0
;
if
lhs
.is_negative
()
{
...
...
@@ -426,6 +430,14 @@ mod tests {
assert_eq!
(
a
.checked_div_int
(
&
0i32
),
None
);
}
#[test]
fn
checked_div_with_zero_dividend_should_be_zero
()
{
let
a
=
Fixed128
::
zero
();
let
b
=
Fixed128
::
from_parts
(
1
);
assert_eq!
(
a
.checked_div
(
&
b
),
Some
(
Fixed128
::
zero
()));
}
#[test]
fn
under_flow_should_be_none
()
{
let
b
=
Fixed128
::
from_natural
(
1
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment