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
057207c2
Unverified
Commit
057207c2
authored
5 years ago
by
Shaopeng Wang
Committed by
GitHub
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add is_positive and is_negative fn to Fixed128. (#121)
parent
9ac56d2f
No related branches found
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
+23
-0
23 additions, 0 deletions
utilities/src/fixed_128.rs
with
23 additions
and
0 deletions
utilities/src/fixed_128.rs
+
23
−
0
View file @
057207c2
...
@@ -185,6 +185,14 @@ impl Fixed128 {
...
@@ -185,6 +185,14 @@ impl Fixed128 {
*
self
*
self
}
}
}
}
pub
fn
is_positive
(
&
self
)
->
bool
{
self
.0
.is_positive
()
}
pub
fn
is_negative
(
&
self
)
->
bool
{
self
.0
.is_negative
()
}
}
}
impl
Saturating
for
Fixed128
{
impl
Saturating
for
Fixed128
{
...
@@ -553,4 +561,19 @@ mod tests {
...
@@ -553,4 +561,19 @@ mod tests {
// saturating
// saturating
assert_eq!
(
Fixed128
::
min_value
()
.saturating_abs
(),
Fixed128
::
max_value
());
assert_eq!
(
Fixed128
::
min_value
()
.saturating_abs
(),
Fixed128
::
max_value
());
}
}
#[test]
fn
is_positive_negative_should_work
()
{
let
positive
=
Fixed128
::
from_parts
(
1
);
assert!
(
positive
.is_positive
());
assert!
(
!
positive
.is_negative
());
let
negative
=
Fixed128
::
from_parts
(
-
1
);
assert!
(
!
negative
.is_positive
());
assert!
(
negative
.is_negative
());
let
zero
=
Fixed128
::
zero
();
assert!
(
!
zero
.is_positive
());
assert!
(
!
zero
.is_negative
());
}
}
}
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