diff options
author | dknn <yoann.blein@free.fr> | 2012-08-10 18:04:56 (GMT) |
---|---|---|
committer | dknn <yoann.blein@free.fr> | 2012-09-22 09:32:38 (GMT) |
commit | 955c4589ca254814ae7ec6ed911e0a62febc5da1 (patch) | |
tree | 1d3ba8ecc732f8239462f7428e758224f3d38b94 /Swiften/Base | |
parent | 577fffec4a1da6909740a392cf76617bdcbe5570 (diff) | |
download | swift-contrib-955c4589ca254814ae7ec6ed911e0a62febc5da1.zip swift-contrib-955c4589ca254814ae7ec6ed911e0a62febc5da1.tar.bz2 |
Capture and send user UI events
Diffstat (limited to 'Swiften/Base')
-rw-r--r-- | Swiften/Base/FloatCompare.h | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/Swiften/Base/FloatCompare.h b/Swiften/Base/FloatCompare.h new file mode 100644 index 0000000..152ffff --- /dev/null +++ b/Swiften/Base/FloatCompare.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2012 Yoann Blein + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#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); + } +} |