Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
SWIFTsim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
SWIFT
SWIFTsim
Commits
ecc621ba
Commit
ecc621ba
authored
7 years ago
by
Jacob Kegerreis
Browse files
Options
Downloads
Patches
Plain Diff
Rename function to keep the non-generality clear
parent
6350e5f6
No related branches found
No related tags found
1 merge request
!547
Add generic utility function to find a value in an array
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/utilities.h
+1
-1
1 addition, 1 deletion
src/utilities.h
tests/testUtilities.c
+6
-6
6 additions, 6 deletions
tests/testUtilities.c
with
7 additions
and
7 deletions
src/utilities.h
+
1
−
1
View file @
ecc621ba
...
...
@@ -30,7 +30,7 @@
*
* Return -1 and n for x below and above the array edge values respectively.
*/
INLINE
static
int
find_value_in_monot
onic
_array
(
INLINE
static
int
find_value_in_monot
_incr
_array
(
const
float
x
,
const
float
*
array
,
const
int
n
)
{
int
index_mid
,
index_low
=
0
,
index_high
=
n
;
...
...
This diff is collapsed.
Click to expand it.
tests/testUtilities.c
+
6
−
6
View file @
ecc621ba
...
...
@@ -24,7 +24,7 @@
* @brief Test generic utility functions
*/
int
main
()
{
/// Test find_value_in_monot
onic
_array()
/// Test find_value_in_monot
_incr
_array()
int
n
=
100
;
float
array
[
n
];
int
index
;
...
...
@@ -37,28 +37,28 @@ int main() {
// Typical value
x
=
42
.
42
f
;
index
=
find_value_in_monot
onic
_array
(
x
,
array
,
n
);
index
=
find_value_in_monot
_incr
_array
(
x
,
array
,
n
);
if
(
index
!=
42
)
{
error
(
"Failed with a typical value "
);
}
// Value on array element
x
=
33
.
f
;
index
=
find_value_in_monot
onic
_array
(
x
,
array
,
n
);
index
=
find_value_in_monot
_incr
_array
(
x
,
array
,
n
);
if
(
index
!=
33
)
{
error
(
"Failed with an array element "
);
}
// Value below array
x
=
-
123
.
f
;
index
=
find_value_in_monot
onic
_array
(
x
,
array
,
n
);
index
=
find_value_in_monot
_incr
_array
(
x
,
array
,
n
);
if
(
index
!=
-
1
)
{
error
(
"Failed with a value below the array "
);
}
// Value above array
x
=
123
.
f
;
index
=
find_value_in_monot
onic
_array
(
x
,
array
,
n
);
index
=
find_value_in_monot
_incr
_array
(
x
,
array
,
n
);
if
(
index
!=
n
)
{
error
(
"Failed with a value above the array "
);
}
...
...
@@ -66,7 +66,7 @@ int main() {
// Array slice with typical value
x
=
9
.
81
f
;
n
=
10
;
index
=
find_value_in_monot
onic
_array
(
x
,
array
+
5
,
n
);
index
=
find_value_in_monot
_incr
_array
(
x
,
array
+
5
,
n
);
if
(
index
!=
4
)
{
error
(
"Failed with an array slice "
);
}
...
...
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