summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordknn <yoann.blein@free.fr>2012-08-17 14:51:37 (GMT)
committerdknn <yoann.blein@free.fr>2012-09-22 09:32:53 (GMT)
commitc8ced8597ab28b928862d21554c0a68c238b1165 (patch)
tree360bc3b3b10afcde3d8cef2558bbec68783285dd
parent65f6d936741cd4487de1b469a5db39fb4fdccf07 (diff)
downloadswift-contrib-c8ced8597ab28b928862d21554c0a68c238b1165.zip
swift-contrib-c8ced8597ab28b928862d21554c0a68c238b1165.tar.bz2
Move float comparison functions to cpp
-rw-r--r--Swiften/Base/FloatCompare.cpp28
-rw-r--r--Swiften/Base/FloatCompare.h20
-rw-r--r--Swiften/Base/SConscript1
3 files changed, 33 insertions, 16 deletions
diff --git a/Swiften/Base/FloatCompare.cpp b/Swiften/Base/FloatCompare.cpp
new file mode 100644
index 0000000..ecf11c2
--- /dev/null
+++ b/Swiften/Base/FloatCompare.cpp
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2012 Yoann Blein
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include <cmath>
+
+namespace Swift {
+
+bool approximatelyEqual(float a, float b, float epsilon) {
+ return std::fabs(a - b) <= ( (std::fabs(a) < std::fabs(b) ? std::fabs(b) : std::fabs(a)) * epsilon);
+}
+
+bool essentiallyEqual(float a, float b, float epsilon) {
+ return std::fabs(a - b) <= ( (std::fabs(a) > std::fabs(b) ? std::fabs(b) : std::fabs(a)) * epsilon);
+}
+
+bool definitelyGreaterThan(float a, float b, float epsilon) {
+ return (a - b) > ( (std::fabs(a) < std::fabs(b) ? std::fabs(b) : std::fabs(a)) * epsilon);
+}
+
+bool definitelyLessThan(float a, float b, float epsilon) {
+ return (b - a) > ( (std::fabs(a) < std::fabs(b) ? std::fabs(b) : std::fabs(a)) * epsilon);
+}
+
+}
+
diff --git a/Swiften/Base/FloatCompare.h b/Swiften/Base/FloatCompare.h
index 152ffff..bf8f930 100644
--- a/Swiften/Base/FloatCompare.h
+++ b/Swiften/Base/FloatCompare.h
@@ -6,23 +6,11 @@
#pragma once
-#include <cmath>
#include <limits>
namespace Swift {
- bool approximatelyEqual(float a, float b, float epsilon = std::numeric_limits<float>::epsilon()) {
- return std::fabs(a - b) <= ( (std::fabs(a) < std::fabs(b) ? std::fabs(b) : std::fabs(a)) * epsilon);
- }
-
- bool essentiallyEqual(float a, float b, float epsilon = std::numeric_limits<float>::epsilon()) {
- return std::fabs(a - b) <= ( (std::fabs(a) > std::fabs(b) ? std::fabs(b) : std::fabs(a)) * epsilon);
- }
-
- bool definitelyGreaterThan(float a, float b, float epsilon = std::numeric_limits<float>::epsilon()) {
- return (a - b) > ( (std::fabs(a) < std::fabs(b) ? std::fabs(b) : std::fabs(a)) * epsilon);
- }
-
- bool definitelyLessThan(float a, float b, float epsilon = std::numeric_limits<float>::epsilon()) {
- return (b - a) > ( (std::fabs(a) < std::fabs(b) ? std::fabs(b) : std::fabs(a)) * epsilon);
- }
+ bool approximatelyEqual(float a, float b, float epsilon = std::numeric_limits<float>::epsilon());
+ bool essentiallyEqual(float a, float b, float epsilon = std::numeric_limits<float>::epsilon());
+ bool definitelyGreaterThan(float a, float b, float epsilon = std::numeric_limits<float>::epsilon());
+ bool definitelyLessThan(float a, float b, float epsilon = std::numeric_limits<float>::epsilon());
}
diff --git a/Swiften/Base/SConscript b/Swiften/Base/SConscript
index 754164b..fbb61ba 100644
--- a/Swiften/Base/SConscript
+++ b/Swiften/Base/SConscript
@@ -14,5 +14,6 @@ objects = swiften_env.SwiftenObject([
"BoostRandomGenerator.cpp",
"sleep.cpp",
"URL.cpp",
+ "FloatCompare.cpp",
])
swiften_env.Append(SWIFTEN_OBJECTS = [objects])