Embedded Template Library
1.0
Loading...
Searching...
No Matches
log.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) 2014 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_LOG_INCLUDED
32
#define ETL_LOG_INCLUDED
33
34
#include "
platform.h
"
35
36
#include <stddef.h>
37
43
44
namespace
etl
45
{
46
//***************************************************************************
53
//***************************************************************************
54
template
<
size_t
NV,
size_t
BASE>
55
struct
log
56
{
57
enum
value_type
58
{
59
// Recursive definition.
60
value = (
NV
>=
BASE
) ? 1 +
log<NV / BASE, BASE>::value
: 0
61
};
62
};
63
64
//***************************************************************************
65
// Specialisation for N = 1
66
//***************************************************************************
67
template
<
size_t
BASE>
68
struct
log
<1,
BASE
>
69
{
70
enum
value_type
71
{
72
value = 0
73
};
74
};
75
76
//***************************************************************************
77
// Specialisation for N = 0
78
//***************************************************************************
79
template
<
size_t
BASE>
80
struct
log
<0,
BASE
>
81
{
82
enum
value_type
83
{
84
value = 0
85
};
86
};
87
88
#if ETL_USING_CPP17
89
template
<
size_t
NV,
size_t
BASE>
90
inline
constexpr
size_t
log_v
=
log<NV, BASE>::value
;
91
#endif
92
93
//***************************************************************************
96
//***************************************************************************
97
template
<
size_t
NV>
98
struct
log2
99
{
100
enum
value_type
101
{
102
value =
log<NV, 2>::value
103
};
104
};
105
106
#if ETL_USING_CPP17
107
template
<
size_t
NV>
108
inline
constexpr
size_t
log2_v
=
log2<NV>::value
;
109
#endif
110
111
//***************************************************************************
114
//***************************************************************************
115
template
<
size_t
NV>
116
struct
log10
117
{
118
enum
value_type
119
{
120
value =
log<NV, 10>::value
121
};
122
};
123
124
#if ETL_USING_CPP17
125
template
<
size_t
NV>
126
inline
constexpr
size_t
log10_v
=
log10<NV>::value
;
127
#endif
128
}
129
130
#endif
etl::log
Definition
log.h:56
etl::log10
Definition
log.h:117
etl::log2
Definition
log.h:99
etl
bitset_ext
Definition
absolute.h:38
platform.h
etl::pair
pair holds two objects of arbitrary type
Definition
utility.h:164
include
etl
log.h
Generated on Tue May 13 2025 04:31:38 for Embedded Template Library by
1.9.8