Embedded Template Library
1.0
Loading...
Searching...
No Matches
math.h
Go to the documentation of this file.
1
2
3
/******************************************************************************
4
The MIT License(MIT)
5
6
Embedded Template Library.
7
https://github.com/ETLCPP/etl
8
https://www.etlcpp.com
9
10
Copyright(c) 2023 John Wellbelove
11
12
Permission is hereby granted, free of charge, to any person obtaining a copy
13
of this software and associated documentation files(the "Software"), to deal
14
in the Software without restriction, including without limitation the rights
15
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
16
copies of the Software, and to permit persons to whom the Software is
17
furnished to do so, subject to the following conditions :
18
19
The above copyright notice and this permission notice shall be included in all
20
copies or substantial portions of the Software.
21
22
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
25
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
SOFTWARE.
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
47
namespace
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
55
typename
etl::enable_if<etl::is_floating_point<T>::value
,
bool
>::type
56
is_nan(T value)
57
{
58
return
fpclassify(value) == FP_NAN;
59
}
60
#else
61
#include "
private/diagnostic_float_equal_push.h
"
62
template
<
typename
T>
63
ETL_CONSTEXPR
64
typename
etl::enable_if<etl::is_floating_point<T>::value
,
bool
>::type
65
is_nan(T value)
66
{
67
return
(value != value);
68
}
69
#include "
private/diagnostic_pop.h
"
70
#endif
71
72
template
<
typename
T>
73
ETL_CONSTEXPR
74
typename
etl::enable_if<etl::is_integral<T>::value
,
bool
>::type
75
is_nan(T)
76
{
77
return
false
;
78
}
79
80
//***************************************************************************
81
// is_infinity
82
//***************************************************************************
83
#if ETL_USING_CPP11 && !defined(ETL_NO_CPP_NAN_SUPPORT)
84
template
<
typename
T>
85
ETL_CONSTEXPR
86
typename
etl::enable_if<etl::is_floating_point<T>::value
,
bool
>::type
87
is_infinity(T value)
88
{
89
return
fpclassify(value) == FP_INFINITE;
90
}
91
#else
92
#include "
private/diagnostic_float_equal_push.h
"
93
template
<
typename
T>
94
ETL_CONSTEXPR
95
typename
etl::enable_if<etl::is_floating_point<T>::value
,
bool
>::type
96
is_infinity(T value)
97
{
98
return
((value ==
etl::numeric_limits<T>::infinity
()) ||
99
(value == -
etl::numeric_limits<T>::infinity
()));
100
}
101
#include "
private/diagnostic_pop.h
"
102
#endif
103
104
template
<
typename
T>
105
ETL_CONSTEXPR
106
typename
etl::enable_if<etl::is_integral<T>::value
,
bool
>::type
107
is_infinity(T)
108
{
109
return
false
;
110
}
111
112
//***************************************************************************
113
// is_zero
114
//***************************************************************************
115
#if ETL_USING_CPP11 && !defined(ETL_NO_CPP_NAN_SUPPORT)
116
template
<
typename
T>
117
ETL_CONSTEXPR
118
typename
etl::enable_if<etl::is_floating_point<T>::value
,
bool
>::type
119
is_zero(T value)
120
{
121
return
fpclassify(value) == FP_ZERO;
122
}
123
#else
124
#include "
private/diagnostic_float_equal_push.h
"
125
template
<
typename
T>
126
ETL_CONSTEXPR
127
typename
etl::enable_if<etl::is_floating_point<T>::value
,
bool
>::type
128
is_zero(T value)
129
{
130
return
value == 0;
131
}
132
#include "
private/diagnostic_pop.h
"
133
#endif
134
135
template
<
typename
T>
136
ETL_CONSTEXPR
137
typename
etl::enable_if<etl::is_integral<T>::value
,
bool
>::type
138
is_zero(T value)
139
{
140
return
(value == 0);
141
}
142
143
//***************************************************************************
144
// is_exactly_equal
145
//***************************************************************************
146
#include "
private/diagnostic_float_equal_push.h
"
147
template
<
typename
T>
148
ETL_CONSTEXPR
149
bool
is_exactly_equal(T value1, T value2)
150
{
151
return
value1 == value2;
152
}
153
#include "
private/diagnostic_pop.h
"
154
}
155
156
#endif
etl::numeric_limits
Definition
limits.h:1175
diagnostic_float_equal_push.h
diagnostic_pop.h
limits.h
math.h
etl
bitset_ext
Definition
absolute.h:38
platform.h
etl::pair
pair holds two objects of arbitrary type
Definition
utility.h:164
type_traits.h
include
etl
math.h
Generated on Thu Jan 2 2025 19:14:45 for Embedded Template Library by
1.9.8