blob: 152ffff91687cb9de71cf49d0528d8b1542e44a1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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);
}
}
|