tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
fma.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_CMATH_FMA_HPP
4#define TETL_CMATH_FMA_HPP
5
6#include <etl/_config/all.hpp>
7
10
11namespace etl {
12
13namespace detail {
14
15inline constexpr struct fma {
16 template <typename Float>
17 [[nodiscard]] constexpr auto operator()(Float x, Float y, Float z) const noexcept -> Float
18 {
19 if (not is_constant_evaluated()) {
20#if __has_builtin(__builtin_fmaf)
21 if constexpr (is_same_v<Float, float>) {
22 return __builtin_fmaf(x, y, z);
23 }
24#endif
25#if __has_builtin(__builtin_fma)
26 if constexpr (is_same_v<Float, double>) {
27 return __builtin_fma(x, y, z);
28 }
29#endif
30 }
31
32 return x * y + z;
33 }
34} fma;
35
36} // namespace detail
37
40
44[[nodiscard]] constexpr auto fma(float x, float y, float z) noexcept -> float { return etl::detail::fma(x, y, z); }
45[[nodiscard]] constexpr auto fmaf(float x, float y, float z) noexcept -> float { return etl::detail::fma(x, y, z); }
46[[nodiscard]] constexpr auto fma(double x, double y, double z) noexcept -> double { return etl::detail::fma(x, y, z); }
47[[nodiscard]] constexpr auto fma(long double x, long double y, long double z) noexcept -> long double
48{
49 return etl::detail::fma(x, y, z);
50}
51[[nodiscard]] constexpr auto fmal(long double x, long double y, long double z) noexcept -> long double
52{
53 return etl::detail::fma(x, y, z);
54}
55
57
58} // namespace etl
59
60#endif // TETL_CMATH_FMA_HPP
constexpr auto fma(float x, float y, float z) noexcept -> float
Computes (x*y) + z as if to infinite precision and rounded only once to fit the result type.
Definition fma.hpp:44
constexpr auto fmal(long double x, long double y, long double z) noexcept -> long double
Computes (x*y) + z as if to infinite precision and rounded only once to fit the result type.
Definition fma.hpp:51
constexpr auto fmaf(float x, float y, float z) noexcept -> float
Computes (x*y) + z as if to infinite precision and rounded only once to fit the result type.
Definition fma.hpp:45
Definition adjacent_find.hpp:8
constexpr auto is_constant_evaluated() noexcept -> bool
Detects whether the function call occurs within a constant-evaluated context. Returns true if the eva...
Definition is_constant_evaluated.hpp:16
constexpr bool is_same_v
Definition is_same.hpp:11