Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
S
src
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
71
Issues
71
List
Boards
Labels
Service Desk
Milestones
Merge Requests
5
Merge Requests
5
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Code Review
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OPAL
src
Commits
1bfb954e
Commit
1bfb954e
authored
Oct 09, 2020
by
gsell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use std::isnan() in almost_eq()
parent
d1603d91
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
8 deletions
+9
-8
src/Structure/BoundaryGeometry.cpp
src/Structure/BoundaryGeometry.cpp
+9
-8
No files found.
src/Structure/BoundaryGeometry.cpp
View file @
1bfb954e
...
...
@@ -222,16 +222,17 @@ namespace cmp_ulp {
See:
https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
*/
inline
bool
almost_eq
(
double
A
,
double
B
,
double
maxDiff
=
1e-20
,
int
maxUlps
=
1000
)
{
inline
bool
almost_eq
(
double
A
,
double
B
,
double
maxDiff
=
1e-20
,
int
maxUlps
=
1000
)
{
// handle NaN's
// Note: comparing something with a NaN is always false!
if
(
A
!=
A
||
B
!=
B
)
{
if
(
std
::
isnan
(
A
)
||
std
::
isnan
(
B
))
{
return
false
;
}
// Check if the numbers are really close -- needed
// when comparing numbers near zero.
if
(
std
::
abs
(
A
-
B
)
<=
maxDiff
)
if
(
std
::
abs
(
A
-
B
)
<=
maxDiff
)
return
true
;
#pragma GCC diagnostic push
...
...
@@ -242,15 +243,15 @@ namespace cmp_ulp {
// Different signs means they do not match.
// Note: a negative floating point number is also negative as integer.
if
(
std
::
signbit
(
aInt
)
!=
std
::
signbit
(
bInt
))
if
(
std
::
signbit
(
aInt
)
!=
std
::
signbit
(
bInt
))
return
false
;
// Find the difference in ULPs.
return
(
std
::
abs
(
aInt
-
bInt
)
<=
maxUlps
);
return
(
std
::
abs
(
aInt
-
bInt
)
<=
maxUlps
);
}
inline
bool
almost_eq_zero
(
double
A
,
double
maxDiff
=
1e-15
)
{
return
(
std
::
abs
(
A
)
<=
maxDiff
);
return
(
std
::
abs
(
A
)
<=
maxDiff
);
}
FUNC_EQ
(
x
,
y
);
FUNC_EQ_ZERO
(
x
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment