Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
arbor
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Analyze
Contributor analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
arbor-sim
arbor
Commits
104e3897
Commit
104e3897
authored
8 years ago
by
Sam Yates
Browse files
Options
Downloads
Patches
Plain Diff
`math::infinity<>()` wrapper for infinity
parent
ddc8537d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/math.hpp
+7
-1
7 additions, 1 deletion
src/math.hpp
tests/unit/CMakeLists.txt
+1
-0
1 addition, 0 deletions
tests/unit/CMakeLists.txt
tests/unit/test_math.cpp
+36
-0
36 additions, 0 deletions
tests/unit/test_math.cpp
with
44 additions
and
1 deletion
src/math.hpp
+
7
−
1
View file @
104e3897
#pragma once
#include
<cmath>
#include
<limits>
#include
<utility>
namespace
nest
{
namespace
mc
{
namespace
math
{
...
...
@@ -14,6 +14,12 @@ T constexpr pi()
return
T
(
3.1415926535897932384626433832795
);
}
template
<
typename
T
=
float
>
T
constexpr
infinity
()
{
return
std
::
numeric_limits
<
T
>::
infinity
();
}
template
<
typename
T
>
T
constexpr
mean
(
T
a
,
T
b
)
{
...
...
This diff is collapsed.
Click to expand it.
tests/unit/CMakeLists.txt
+
1
−
0
View file @
104e3897
...
...
@@ -12,6 +12,7 @@ set(TEST_SOURCES
test_cell_group.cpp
test_lexcmp.cpp
test_mask_stream.cpp
test_math.cpp
test_matrix.cpp
test_mechanisms.cpp
test_nop.cpp
...
...
This diff is collapsed.
Click to expand it.
tests/unit/test_math.cpp
0 → 100644
+
36
−
0
View file @
104e3897
#include
<cmath>
#include
<limits>
#include
"gtest.h"
#include
<math.hpp>
using
namespace
nest
::
mc
::
math
;
TEST
(
math
,
infinity
)
{
// check values for float, double, long double
auto
finf
=
infinity
<
float
>
();
EXPECT_TRUE
((
std
::
is_same
<
float
,
decltype
(
finf
)
>::
value
));
EXPECT_TRUE
(
std
::
isinf
(
finf
));
EXPECT_GT
(
finf
,
0.
f
);
auto
dinf
=
infinity
<
double
>
();
EXPECT_TRUE
((
std
::
is_same
<
double
,
decltype
(
dinf
)
>::
value
));
EXPECT_TRUE
(
std
::
isinf
(
dinf
));
EXPECT_GT
(
dinf
,
0.0
);
auto
ldinf
=
infinity
<
long
double
>
();
EXPECT_TRUE
((
std
::
is_same
<
long
double
,
decltype
(
ldinf
)
>::
value
));
EXPECT_TRUE
(
std
::
isinf
(
ldinf
));
EXPECT_GT
(
ldinf
,
0.0
l
);
// check default value promotes correctly (i.e., acts like INFINITY)
struct
{
float
f
;
double
d
;
long
double
ld
;
}
check
=
{
infinity
<>
(),
infinity
<>
(),
infinity
<>
()};
EXPECT_EQ
(
std
::
numeric_limits
<
float
>::
infinity
(),
check
.
f
);
EXPECT_EQ
(
std
::
numeric_limits
<
double
>::
infinity
(),
check
.
d
);
EXPECT_EQ
(
std
::
numeric_limits
<
long
double
>::
infinity
(),
check
.
ld
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
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