summaryrefslogtreecommitdiff
path: root/compiler/nike/include/nike/RelativeEpsilonEqual.h
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/nike/include/nike/RelativeEpsilonEqual.h')
-rw-r--r--compiler/nike/include/nike/RelativeEpsilonEqual.h50
1 files changed, 50 insertions, 0 deletions
diff --git a/compiler/nike/include/nike/RelativeEpsilonEqual.h b/compiler/nike/include/nike/RelativeEpsilonEqual.h
new file mode 100644
index 000000000..1b4c04a12
--- /dev/null
+++ b/compiler/nike/include/nike/RelativeEpsilonEqual.h
@@ -0,0 +1,50 @@
+/*
+ * 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.
+ */
+
+#ifndef __NIKE_RELATIVE_EPSILON_EQUAL_H__
+#define __NIKE_RELATIVE_EPSILON_EQUAL_H__
+
+namespace nike
+{
+
+class RelativeEpsilonEqualFunctor
+{
+public:
+ friend RelativeEpsilonEqualFunctor relative_epsilon_equal(unsigned);
+
+private:
+ RelativeEpsilonEqualFunctor(unsigned tolerance) : _tolerance{tolerance}
+ {
+ // DO NOTHING
+ }
+
+public:
+ bool operator()(float lhs, float rhs) const;
+
+private:
+ unsigned _tolerance;
+};
+
+/**
+ * @note RelativeEpsilonEqualFunctor uses its own rule for NaN values.
+ *
+ * For example, "NAN == NAN" is false but "relative_epsilon_equal(1)(NAN, NAN)" is true.
+ */
+RelativeEpsilonEqualFunctor relative_epsilon_equal(unsigned tolerance);
+
+} // namespace nike
+
+#endif // __NIKE_RELATIVE_EPSILON_EQUAL_H__