1 /*
2  * Copyright (c) 2019-2020 Kevin Townsend (KTOWN)
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /**
8  * @file
9  * @brief Helper functions to test floating point values.
10  *
11  * This file contains helpers to test floating point values.
12  */
13 
14 #ifndef ZEPHYR_INCLUDE_ZSL_FLOATCHECK_H_
15 #define ZEPHYR_INCLUDE_ZSL_FLOATCHECK_H_
16 
17 #include <zephyr/kernel.h>
18 #include <stdint.h>
19 #include <zsl/zsl.h>
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 /**
26  * Checks if a zsl_real_t is equal to the specified value, with a +/- margin of
27  * 'epsilon'.
28  *
29  * @param a         The value to check
30  * @param b         The value to compare against
31  * @param epsilon   The +/- margin for equality
32  *
33  * @return  True if value 'a' is equal to 'b', otherwise false.
34  */
35 bool val_is_equal(zsl_real_t a, zsl_real_t b, zsl_real_t epsilon);
36 
37 /**
38  * Checks if a zsl_real_t is equal to or greater than the specified value.
39  *
40  * @param a         The value to check
41  * @param b         The value to compare against
42  *
43  * @return  True if value 'a' is greater than or equal to 'b', otherwise false.
44  */
45 bool val_is_at_least(zsl_real_t a, zsl_real_t b);
46 
47 /**
48  * Checks if a zsl_real_t is less than the specified value.
49  *
50  * @param a         The value to check
51  * @param b         The value to compare against
52  *
53  * @return  True if value 'a' is less than 'b', otherwise false.
54  */
55 bool val_is_less_than(zsl_real_t a, zsl_real_t b);
56 
57 /**
58  * Checks if a zsl_real_t is greater than the specified value.
59  *
60  * @param a         The value to check
61  * @param b         The value to compare against
62  *
63  * @return  True if value 'a' is greater than 'b', otherwise false.
64  */
65 bool val_is_greater_than(zsl_real_t a, zsl_real_t b);
66 
67 /**
68  * Checks if a zsl_real_t is within the range of 'upper' and 'lower'.
69  *
70  * @param a         The value to check
71  * @param upper     The upper value to compare against (inclusive)
72  * @param lower     The lower value to compare against (inclusive)
73  *
74  * @return  True if value 'a' is <= 'upper' and >='lower', otherwise false.
75  */
76 bool val_is_within(zsl_real_t a, zsl_real_t upper, zsl_real_t lower);
77 
78 #ifdef __cplusplus
79 }
80 #endif
81 
82 #endif /* _MB_FLOATCHECK_H_ */
83