WPILibC++ 2024.3.2
log10.hpp
Go to the documentation of this file.
1/*################################################################################
2 ##
3 ## Copyright (C) 2016-2023 Keith O'Hara
4 ##
5 ## This file is part of the GCE-Math C++ library.
6 ##
7 ## Licensed under the Apache License, Version 2.0 (the "License");
8 ## you may not use this file except in compliance with the License.
9 ## You may obtain a copy of the License at
10 ##
11 ## http://www.apache.org/licenses/LICENSE-2.0
12 ##
13 ## Unless required by applicable law or agreed to in writing, software
14 ## distributed under the License is distributed on an "AS IS" BASIS,
15 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 ## See the License for the specific language governing permissions and
17 ## limitations under the License.
18 ##
19 ################################################################################*/
20
21/*
22 * compile-time common logarithm function
23 */
24
25#ifndef _gcem_log10_HPP
26#define _gcem_log10_HPP
27
28#include <cmath>
29#include <type_traits>
30
31namespace gcem
32{
33
34namespace internal
35{
36
37template<typename T>
38constexpr
39return_t<T>
40log10_check(const T x)
41noexcept
42{
43 // log_10(x) = ln(x) / ln(10)
44 return return_t<T>(log(x) / GCEM_LOG_10);
45}
46
47}
48
49/**
50 * Compile-time common logarithm function
51 *
52 * @param x a real-valued input.
53 * @return \f$ \log_{10}(x) \f$ using \f[ \log_{10}(x) = \frac{\log_e(x)}{\log_e(10)} \f]
54 */
55
56template<typename T>
57constexpr
58return_t<T>
59log10(const T x)
60noexcept
61{
63 return internal::log10_check( x );
64 } else {
65 return std::log10(x);
66 }
67}
68
69}
70
71#endif
#define GCEM_LOG_10
Definition: gcem_options.hpp:94
constexpr FMT_INLINE auto is_constant_evaluated(bool default_value=false) noexcept -> bool
Definition: core.h:304
constexpr return_t< T > log10_check(const T x) noexcept
Definition: log10.hpp:40
Definition: is_even.hpp:29
constexpr return_t< T > log10(const T x) noexcept
Compile-time common logarithm function.
Definition: log10.hpp:59
constexpr return_t< T > log(const T x) noexcept
Compile-time natural logarithm function.
Definition: log.hpp:186
typename std::conditional< std::is_integral< T >::value, double, T >::type return_t
Definition: gcem_options.hpp:77