Embedded Template Library 1.0
Loading...
Searching...
No Matches
math.h
Go to the documentation of this file.
1
2
3/******************************************************************************
4The MIT License(MIT)
5
6Embedded Template Library.
7https://github.com/ETLCPP/etl
8https://www.etlcpp.com
9
10Copyright(c) 2023 John Wellbelove
11
12Permission is hereby granted, free of charge, to any person obtaining a copy
13of this software and associated documentation files(the "Software"), to deal
14in the Software without restriction, including without limitation the rights
15to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
16copies of the Software, and to permit persons to whom the Software is
17furnished to do so, subject to the following conditions :
18
19The above copyright notice and this permission notice shall be included in all
20copies or substantial portions of the Software.
21
22THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
25AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28SOFTWARE.
29******************************************************************************/
30
31#ifndef ETL_MATH_INCLUDED
32#define ETL_MATH_INCLUDED
33
34#include "platform.h"
35
36#if ETL_NOT_USING_STL && defined(ETL_COMPILER_ARM5) && !defined(__USE_C99_MATH)
37 // Required for nan, nanf, nanl
38 #define __USE_C99_MATH
39#endif
40
41#include <float.h>
42#include <math.h>
43
44#include "limits.h"
45#include "type_traits.h"
46
47namespace etl
48{
49 //***************************************************************************
50 // is_nan
51 //***************************************************************************
52#if ETL_USING_CPP11 && !defined(ETL_NO_CPP_NAN_SUPPORT)
53 template <typename T>
54 ETL_CONSTEXPR typename etl::enable_if<etl::is_floating_point<T>::value, bool>::type is_nan(T value)
55 {
56 return fpclassify(value) == FP_NAN;
57 }
58#else
60 template <typename T>
61 ETL_CONSTEXPR typename etl::enable_if<etl::is_floating_point<T>::value, bool>::type is_nan(T value)
62 {
63 return (value != value);
64 }
66#endif
67
68 template <typename T>
69 ETL_CONSTEXPR typename etl::enable_if<etl::is_integral<T>::value, bool>::type is_nan(T)
70 {
71 return false;
72 }
73
74 //***************************************************************************
75 // is_infinity
76 //***************************************************************************
77#if ETL_USING_CPP11 && !defined(ETL_NO_CPP_NAN_SUPPORT)
78 template <typename T>
79 ETL_CONSTEXPR typename etl::enable_if<etl::is_floating_point<T>::value, bool>::type is_infinity(T value)
80 {
81 return fpclassify(value) == FP_INFINITE;
82 }
83#else
85 template <typename T>
86 ETL_CONSTEXPR typename etl::enable_if<etl::is_floating_point<T>::value, bool>::type is_infinity(T value)
87 {
88 return ((value == etl::numeric_limits<T>::infinity()) || (value == -etl::numeric_limits<T>::infinity()));
89 }
91#endif
92
93 template <typename T>
94 ETL_CONSTEXPR typename etl::enable_if<etl::is_integral<T>::value, bool>::type is_infinity(T)
95 {
96 return false;
97 }
98
99 //***************************************************************************
100 // is_zero
101 //***************************************************************************
102#if ETL_USING_CPP11 && !defined(ETL_NO_CPP_NAN_SUPPORT)
103 template <typename T>
104 ETL_CONSTEXPR typename etl::enable_if<etl::is_floating_point<T>::value, bool>::type is_zero(T value)
105 {
106 return fpclassify(value) == FP_ZERO;
107 }
108#else
110 template <typename T>
111 ETL_CONSTEXPR typename etl::enable_if<etl::is_floating_point<T>::value, bool>::type is_zero(T value)
112 {
113 return value == 0;
114 }
115 #include "private/diagnostic_pop.h"
116#endif
117
118 template <typename T>
119 ETL_CONSTEXPR typename etl::enable_if<etl::is_integral<T>::value, bool>::type is_zero(T value)
120 {
121 return (value == 0);
122 }
123
124 //***************************************************************************
125 // is_exactly_equal
126 //***************************************************************************
128 template <typename T>
129 ETL_CONSTEXPR bool is_exactly_equal(T value1, T value2)
130 {
131 return value1 == value2;
132 }
134} // namespace etl
135
136#endif
Two pairs of the same type are equal if their members are equal.
bitset_ext
Definition absolute.h:40