BeNumerical.h
Go to the documentation of this file.
1 /*--------------------------------------------------------------------------------------+
2 |
3 | Supplied under applicable software license agreement.
4 |
6 |
7 +---------------------------------------------------------------------------------------*/
8 #pragma once
9
11
12 #include "Bentley.h"
13 #include <math.h>
14 #include <float.h>
15 #include <algorithm>
16
18
21
22 /*=================================================================================**/
27 {
28 static double BeNextafter (double x, double y) {return _nextafter(x,y);}
29 static int BeIsnan (double v) {return _isnan(v);}
30 static int BeFinite (double v) {return _finite(v);}
31
33  BENTLEYDLL_EXPORT static UInt32 ResetFloatingPointExceptions (UInt32 newFpuMask);
34
37  static double NextafterDelta (double sv)
38  {
39  double v = fabs (sv);
40  return BeNextafter (v, DBL_MAX) - v;
41  }
42
47  static double ComputeComparisonTolerance (double sv1, double sv2)
48  {
49  double uv = std::max<double> (fabs(sv1), fabs(sv2));
50  return (uv < 1.0)? DBL_EPSILON: NextafterDelta(uv);
51  }
52
57  static int Compare (double sv1, double sv2)
58  {
59  if (fabs (sv2 - sv1) < ComputeComparisonTolerance (sv1, sv2))
60  return 0;
61  return sv1 < sv2? -1: 1;
62  }
63 };
64
66
68
static int BeIsnan(double v)
Definition: BeNumerical.h:29
#define BENTLEYDLL_EXPORT
Definition: Bentley.h:249
Numerical utilities.
Definition: BeNumerical.h:26
uint32_t UInt32
Definition: Bentley.r.h:128
#define BEGIN_BENTLEY_NAMESPACE
Definition: Bentley.r.h:24
static int Compare(double sv1, double sv2)
Compare two values to the closest tolerance possible.
Definition: BeNumerical.h:57
static double NextafterDelta(double sv)
Get the smallest value that, when added to fabs(sv), yields a number that is not equal to fabs(sv)...
Definition: BeNumerical.h:37
static double ComputeComparisonTolerance(double sv1, double sv2)
Compute the tolerance that should be used to check if these two numbers are not equal.
Definition: BeNumerical.h:47
Defines typedefs and constants that can be used across other namespaces. All Bentley-authored C++ sou...
static double BeNextafter(double x, double y)
Definition: BeNumerical.h:28
#define END_BENTLEY_NAMESPACE
Definition: Bentley.r.h:25
static int BeFinite(double v)
Definition: BeNumerical.h:30