Embedded Template Library
1.0
Toggle main menu visibility
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
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
59
#include "
private/diagnostic_float_equal_push.h
"
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
}
65
#include "
private/diagnostic_pop.h
"
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
84
#include "
private/diagnostic_float_equal_push.h
"
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
}
90
#include "
private/diagnostic_pop.h
"
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
109
#include "
private/diagnostic_float_equal_push.h
"
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
//***************************************************************************
127
#include "
private/diagnostic_float_equal_push.h
"
128
template
<
typename
T>
129
ETL_CONSTEXPR
bool
is_exactly_equal(T value1, T value2)
130
{
131
return
value1 == value2;
132
}
133
#include "
private/diagnostic_pop.h
"
134
}
// namespace etl
135
136
#endif
diagnostic_float_equal_push.h
Two pairs of the same type are equal if their members are equal.
diagnostic_pop.h
limits.h
math.h
etl
Definition
absolute.h:40
platform.h
type_traits.h
include
etl
math.h
Generated on
for Embedded Template Library by
1.17.0