MathLib
Loading...
Searching...
No Matches
Checks.hpp
Go to the documentation of this file.
1#pragma once
2
4#include <format>
5#include <iostream>
6
14namespace Math
15{
16
33inline bool check_if_equal(float input, float near_to, float tolerance = 0.0002f)
34{
35 if (!approximately_equal_to(input, near_to, tolerance))
36 {
37 std::cout << std::format("input: {:.6} is not equal to near_to: {:.6} within tolerance: {:.6}. Difference is {:.6}.", input, near_to, tolerance, near_to - input) << std::endl;
38 return false;
39 }
40 return true;
41}
42
43inline bool check_if_equal(double input, double near_to, double tolerance = 0.0002)
44{
45 if (!approximately_equal_to(input, near_to, tolerance))
46 {
47 std::cout << std::format("input: {:.6} is not equal to near_to: {:.6} within tolerance: {:.6}. Difference is {:.6}.", input, near_to, tolerance, near_to - input) << std::endl;
48 return false;
49 }
50 return true;
51}
52
53inline bool check_if_equal(long double input, long double near_to, long double tolerance = 0.0002l)
54{
55 if (!approximately_equal_to(input, near_to, tolerance))
56 {
57 std::cout << std::format("input: {:.6} is not equal to near_to: {:.6} within tolerance: {:.6}. Difference is {:.6}.", input, near_to, tolerance, near_to - input) << std::endl;
58 return false;
59 }
60 return true;
61}
64
81inline bool check_if_not_equal(float input, float near_to, float tolerance = 0.0002f)
82{
83 if (approximately_equal_to(input, near_to, tolerance))
84 {
85 std::cout << std::format("input: {:.6} is not equal to near_to: {:.6} within tolerance: {:.6}. Difference is {:.6}.", input, near_to, tolerance, near_to - input) << std::endl;
86 return false;
87 }
88 return true;
89}
90
91inline bool check_if_not_equal(double input, double near_to, double tolerance = 0.0002)
92{
93 if (approximately_equal_to(input, near_to, tolerance))
94 {
95 std::cout << std::format("input: {:.6} is not equal to near_to: {:.6} within tolerance: {:.6}. Difference is {:.6}.", input, near_to, tolerance, near_to - input) << std::endl;
96 return false;
97 }
98 return true;
99}
100
101inline bool check_if_not_equal(long double input, long double near_to, long double tolerance = 0.0002l)
102{
103 if (approximately_equal_to(input, near_to, tolerance))
104 {
105 std::cout << std::format("input: {:.6} is not equal to near_to: {:.6} within tolerance: {:.6}. Difference is {:.6}.", input, near_to, tolerance, near_to - input) << std::endl;
106 return false;
107 }
108 return true;
109}
112
127inline void CHECK_IF_EQUAL(float input, float near_to, float tolerance = 0.0002f)
128{
129 assert( check_if_equal(input, near_to, tolerance) );
130}
131
132inline void CHECK_IF_EQUAL(double input, double near_to, double tolerance = 0.0002)
133{
134 assert( check_if_equal(input, near_to, tolerance) );
135}
136
137inline void CHECK_IF_EQUAL(long double input, long double near_to, long double tolerance = 0.0002l)
138{
139 assert( check_if_equal(input, near_to, tolerance) );
140}
143
158inline void CHECK_IF_NOT_EQUAL(float input, float near_to, float tolerance = 0.0002f)
159{
160 assert( check_if_not_equal(input, near_to, tolerance) );
161}
162
163inline void CHECK_IF_NOT_EQUAL(double input, double near_to, double tolerance = 0.0002)
164{
165 assert( check_if_not_equal(input, near_to, tolerance) );
166}
167
168inline void CHECK_IF_NOT_EQUAL(long double input, long double near_to, long double tolerance = 0.0002l)
169{
170 assert( check_if_not_equal(input, near_to, tolerance) );
171}
174
189inline void CHECK_IF_ZERO(float input, float tolerance = 0.0002f)
190{
191 assert( check_if_equal(input, 0.0f, tolerance) );
192}
193
194inline void CHECK_IF_ZERO(double input, double tolerance = 0.0002)
195{
196 assert( check_if_equal(input, 0.0, tolerance) );
197}
198
199inline void CHECK_IF_ZERO(long double input, long double tolerance = 0.0002l)
200{
201 assert( check_if_equal(input, 0.0l, tolerance) );
202}
205
206}
void CHECK_IF_NOT_EQUAL(float input, float near_to, float tolerance=0.0002f)
Definition Checks.hpp:158
void CHECK_IF_EQUAL(float input, float near_to, float tolerance=0.0002f)
Definition Checks.hpp:127
void CHECK_IF_ZERO(float input, float tolerance=0.0002f)
Definition Checks.hpp:189
bool check_if_equal(float input, float near_to, float tolerance=0.0002f)
Definition Checks.hpp:33
bool check_if_not_equal(float input, float near_to, float tolerance=0.0002f)
Definition Checks.hpp:81
bool approximately_equal_to(float input, float near_to, float tolerance=0.0002f)
Definition Angle.hpp:16