imate
C++/CUDA Reference
Loading...
Searching...
No Matches
_c_is_equal.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: Copyright 2021, Siavash Ameli <sameli@berkeley.edu>
3 * SPDX-License-Identifier: BSD-3-Clause
4 * SPDX-FileType: SOURCE
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the license found in the LICENSE.txt file in the root
8 * directory of this source tree.
9 */
10
11#ifndef _C_ARITHMETICS_C_IS_EQUAL_H_
12#define _C_ARITHMETICS_C_IS_EQUAL_H_
13
14
15// =======
16// Headers
17// =======
18
19#include <cmath> // std::fabs
20#include <limits> // epsilon
21
22// =============
23// c arithmetics
24// =============
25
31
32namespace c_arithmetics
33{
34
35 // ========
36 // is equal
37 // ========
38
47
48 template <typename DataType>
49 inline bool is_equal(DataType x, DataType y)
50 {
51 if (std::fabs(x - y) <= 2.0 * std::numeric_limits<DataType>::epsilon())
52 {
53 return true;
54 }
55 else
56 {
57 return false;
58 }
59 }
60
61} // namepsace c_arithmetics
62
63#endif // _C_ARITHMETICS_C_IS_EQUAL_H_
This namespace declares arithmetic functions in C.
bool is_equal(DataType x, DataType y)
Check if two floating point numbers are equal within a tolerance.
Definition _c_is_equal.h:49