summaryrefslogtreecommitdiff
path: root/sal
diff options
context:
space:
mode:
Diffstat (limited to 'sal')
-rw-r--r--sal/inc/rtl/math.hxx13
1 files changed, 13 insertions, 0 deletions
diff --git a/sal/inc/rtl/math.hxx b/sal/inc/rtl/math.hxx
index 2018308f9c6c..8f4991a378d0 100644
--- a/sal/inc/rtl/math.hxx
+++ b/sal/inc/rtl/math.hxx
@@ -263,6 +263,19 @@ inline bool approxEqual(double a, double b)
< ((a < 0.0 ? -a : a) * (1.0 / (16777216.0 * 16777216.0)));
}
+/** Test equality of two values with an accuracy defined by nPrec
+
+ @attention
+ approxEqual( value!=0.0, 0.0 ) _never_ yields true.
+ */
+inline bool approxEqual(double a, double b, sal_Int16 nPrec)
+{
+ if ( a == b )
+ return true;
+ double x = a - b;
+ return (x < 0.0 ? -x : x)
+ < ((a < 0.0 ? -a : a) * (1.0 / (pow(2, nPrec))));
+}
/** Add two values.
If signs differ and the absolute values are equal according to approxEqual()