GCC Code Coverage Report


Directory: include/polyfloat/
File: include/polyfloat/module/core/lerp.hpp
Date: 2026-11-09 15:28:50
Exec Total Coverage
Lines: 9 9 100.0%
Functions: 12 12 100.0%
Branches: 0 0 -%

Line Branch Exec Source
1 //======================================================================================================================
2 /*
3 POLYFLOAT - Extended precision floating points
4 Copyright : POLYFLOAT Contributors & Maintainers
5 SPDX-License-Identifier: BSL-1.0
6 */
7 //======================================================================================================================
8 #pragma once
9
10 #include <polyfloat/details/callable.hpp>
11 #include <polyfloat/types/concepts.hpp>
12 #include <polyfloat/types/traits.hpp>
13 #include <type_traits>
14 #include <polyfloat/module/core/abs.hpp>
15
16 namespace plf
17 {
18
19 template<typename Options> struct lerp_t : eve::strict_tuple_callable<lerp_t, Options, raw_option, pedantic_option>
20 {
21 template<typename... Ts> struct result : as_polyfloat_like<Ts...>
22 {
23 };
24
25 template<concepts::polyfloat_like Z0, concepts::polyfloat_like Z1, concepts::polyfloat_like Z2>
26 8 POLYFLOAT_ABI typename result<Z0, Z1, Z2>::type constexpr operator()(Z0 z0, Z1 z1, Z2 z2) const noexcept
27 {
28 8 return POLYFLOAT_CALL(z0, z1, z2);
29 }
30
31 8 POLYFLOAT_CALLABLE_OBJECT(lerp_t, lerp_);
32 };
33 //======================================================================================================================
34 //! @addtogroup core
35 //! @{
36 //! @var lerp
37 //! @brief return the fused multiply add of the parameters.
38 //!
39 //! @groupheader{Header file}
40 //!
41 //! @code
42 //! #include <polyfloat/core.hpp>
43 //! @endcode
44 //!
45 //! @groupheader{Callable Signatures}
46 //!
47 //! @code
48 //! namespace polyfloat
49 //! {
50 //! template<polyfloat::concepts::polyfloat_like Z1, polyfloat_like Z2, polyfloat_like Z3> constexpr auto lerp(Z1 z1, Z2 z2, Z3 z3) noexcept;
51 //! }
52 //! @endcode
53 //!
54 //! **Parameters**
55 //!
56 //! * `z1`, `z2`, `z3`: Values to process.
57 //!
58 //! **Return value**
59 //!
60 //! The value of the interpolation (or extrapolation) between `z1` and `z2` is returned.
61 //! The call is semantically equivalent to `z1+z3*(z2-z1)`
62 //!
63 //! @groupheader{Example}
64 //!
65 //! @godbolt_todo{doc/core/lerp.cpp}
66 //======================================================================================================================
67
68 inline constexpr auto lerp = eve::functor<lerp_t>;
69 //======================================================================================================================
70 //! @}
71 //======================================================================================================================
72 }
73
74 namespace plf::_
75 {
76 template<typename Z1, typename Z2, typename Z3, eve::callable_options O>
77 8 constexpr auto lerp_(POLYFLOAT_DELAY(), O const&, Z1 const& x, Z2 const& y, Z3 const& z) noexcept
78 {
79 using r_t = as_polyfloat_t<Z1, Z2, Z3>;
80 12 auto cvt = [](auto a) { return plf::convert(a, eve::as<eve::element_type_t<r_t>>()); };
81 8 auto a = cvt(x);
82 8 auto b = cvt(y);
83 8 auto t = cvt(z);
84 8 return fma[pedantic](t, b, fnma[pedantic](t, a, a));
85 }
86 }
87