numerical-collection-cpp 0.10.0
A collection of algorithms in numerical analysis implemented in C++
Loading...
Searching...
No Matches
expm1.h
Go to the documentation of this file.
1/*
2 * Copyright 2021 MusicScience37 (Kenta Kabashima)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
20#pragma once
21
22#include <type_traits>
23
26#include "num_collect/constants/one.h" // IWYU pragma: keep
27#include "num_collect/constants/zero.h" // IWYU pragma: keep
28
29namespace num_collect::constants {
30
48template <typename T, typename = std::enable_if_t<std::is_floating_point_v<T>>>
49constexpr auto expm1(T x) -> T {
50 if (x < -one<T> || one<T> < x) {
51 return exp(x) - one<T>;
52 }
53
54 if (x >= zero<T>) {
55 return impl::expm1_maclaurin(x);
56 }
57
58 T expm1_neg = impl::expm1_maclaurin(-x);
59 return -expm1_neg / (expm1_neg + one<T>);
60}
61
62} // namespace num_collect::constants
Definition of exp function.
Definition of expm1_maclaurin function.
constexpr auto expm1_maclaurin(T x) -> T
Calculate exponential function minus one with Maclaurin series.
Namespace of constexpr variables and functions.
Definition cbrt.h:24
constexpr auto exp(T x) -> T
Calculate exponential function .
Definition exp.h:46
constexpr T zero
Value 0.
Definition zero.h:30
constexpr T one
Value 1.
Definition one.h:30
constexpr auto expm1(T x) -> T
Calculate exponential function minus one .
Definition expm1.h:49
Definition of one.
Definition of zero.