Embedded Template Library 1.0
Loading...
Searching...
No Matches
log.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) 2014 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_LOG_INCLUDED
32#define ETL_LOG_INCLUDED
33
34#include "platform.h"
35
36#include <stddef.h>
37
43
44namespace 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
Definition log.h:56
Definition log.h:117
Definition log.h:99
bitset_ext
Definition absolute.h:38
pair holds two objects of arbitrary type
Definition utility.h:164