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
56 is_nan(T value)
57 {
58 return fpclassify(value) == FP_NAN;
59 }
60#else
62 template <typename T>
63 ETL_CONSTEXPR
65 is_nan(T value)
66 {
67 return (value != value);
68 }
70#endif
71
72 template <typename T>
73 ETL_CONSTEXPR
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
87 is_infinity(T value)
88 {
89 return fpclassify(value) == FP_INFINITE;
90 }
91#else
93 template <typename T>
94 ETL_CONSTEXPR
96 is_infinity(T value)
97 {
98 return ((value == etl::numeric_limits<T>::infinity()) ||
100 }
102#endif
103
104 template <typename T>
105 ETL_CONSTEXPR
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
119 is_zero(T value)
120 {
121 return fpclassify(value) == FP_ZERO;
122 }
123#else
125 template <typename T>
126 ETL_CONSTEXPR
128 is_zero(T value)
129 {
130 return value == 0;
131 }
133#endif
134
135 template <typename T>
136 ETL_CONSTEXPR
138 is_zero(T value)
139 {
140 return (value == 0);
141 }
142
143 //***************************************************************************
144 // is_exactly_equal
145 //***************************************************************************
147 template <typename T>
148 ETL_CONSTEXPR
149 bool is_exactly_equal(T value1, T value2)
150 {
151 return value1 == value2;
152 }
154}
155
156#endif
Definition limits.h:1175
bitset_ext
Definition absolute.h:38
pair holds two objects of arbitrary type
Definition utility.h:164