1 /*
2 * Copyright (c) 2019-2020 Kevin Townsend (KTOWN)
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <ctype.h>
8 #include "floatcheck.h"
9
10 bool
val_is_equal(zsl_real_t a,zsl_real_t b,zsl_real_t epsilon)11 val_is_equal(zsl_real_t a, zsl_real_t b, zsl_real_t epsilon)
12 {
13 zsl_real_t c;
14
15 c = a - b;
16
17 if (c < epsilon && -c < epsilon) {
18 return 1;
19 } else {
20 return 0;
21 }
22 }
23
24 bool
val_is_at_least(zsl_real_t a,zsl_real_t b)25 val_is_at_least(zsl_real_t a, zsl_real_t b)
26 {
27 return a >= b ? 1 : 0;
28 }
29
30 bool
val_is_less_than(zsl_real_t a,zsl_real_t b)31 val_is_less_than(zsl_real_t a, zsl_real_t b)
32 {
33 return a < b ? 1 : 0;
34 }
35
36 bool
val_is_greater_than(zsl_real_t a,zsl_real_t b)37 val_is_greater_than(zsl_real_t a, zsl_real_t b)
38 {
39 return a > b ? 1 : 0;
40 }
41
42 bool
val_is_within(zsl_real_t a,zsl_real_t upper,zsl_real_t lower)43 val_is_within(zsl_real_t a, zsl_real_t upper, zsl_real_t lower)
44 {
45 if ((a <= upper) && (a >= lower)) {
46 return 1;
47 } else {
48 return 0;
49 }
50 }
51