Introduce more general approach to compare double values
(based on epsilon) than operator==
---
lib.cpp | 12 ++++++++++--
lib.h | 4 +++-
2 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/lib.cpp b/lib.cpp
index 9b6e04c..e407767 100644
--- a/lib.cpp
+++ b/lib.cpp
@@ -53,7 +53,8 @@ extern "C" {
#include <string.h>
#include <locale.h>
#include <libintl.h>
-
+#include <limits>
+#include <math.h>
static int kallsyms_read = 0;
@@ -364,4 +365,11 @@ char *pretty_print(const char *str, char *buf, int len)
if (len)
buf[len - 1] = 0;
return buf;
-}
\ No newline at end of file
+}
+
+inline int equals(double a, double b)
+{
+ return fabs(a - b) <= std::numeric_limits<double>::epsilon();
+}
+
+
diff --git a/lib.h b/lib.h
index ccf6cda..788b9eb 100644
--- a/lib.h
+++ b/lib.h
@@ -69,5 +69,7 @@ extern void end_pci_access(void);
extern char *fmt_prefix(double n, char *buf);
extern char *pretty_print(const char *str, char *buf, int len);
+extern int equals(double a, double b);
+
+#endif
-#endif
\ No newline at end of file
_______________________________________________
Discuss mailing list
[email protected]
http://lists.lesswatts.org/listinfo/discuss