diff options
Diffstat (limited to 'compiler/nike/src/AbsoluteEpsilonEqual.cpp')
-rw-r--r-- | compiler/nike/src/AbsoluteEpsilonEqual.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/compiler/nike/src/AbsoluteEpsilonEqual.cpp b/compiler/nike/src/AbsoluteEpsilonEqual.cpp new file mode 100644 index 000000000..5877ee84f --- /dev/null +++ b/compiler/nike/src/AbsoluteEpsilonEqual.cpp @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "nike/AbsoluteEpsilonEqual.h" + +#include <cmath> +#include <cfloat> + +namespace nike +{ + +bool AbsoluteEpsilonEqualFunctor::operator()(float lhs, float rhs) const +{ + if (std::isnan(lhs) && std::isnan(rhs)) + { + return true; + } + + const auto diff = std::fabs(lhs - rhs); + + return diff <= _tolerance; +} + +AbsoluteEpsilonEqualFunctor absolute_epsilon_equal(float tolerance) +{ + return AbsoluteEpsilonEqualFunctor{tolerance}; +} + +} // namespace nike |