GCC Code Coverage Report


Directory: include/polyfloat/
File: include/polyfloat/module/core/convert.hpp
Date: 2026-11-09 15:28:50
Exec Total Coverage
Lines: 16 16 100.0%
Functions: 165 165 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
12 namespace plf
13 {
14 template<typename Options> struct convert_t : eve::callable<convert_t, Options>
15 {
16 template<concepts::polyfloat V, concepts::scalar_polyfloat Tgt>
17 76763522 POLYFLOAT_ABI constexpr eve::as_wide_as_t<Tgt, V> operator()(V v, as<Tgt> tgt) const noexcept
18 requires(dimension_v<V> <= dimension_v<Tgt>)
19 {
20 76763522 return POLYFLOAT_CALL(v, tgt);
21 }
22
23 template<concepts::real V, concepts::scalar_polyfloat Tgt>
24 9573768 POLYFLOAT_ABI constexpr eve::as_wide_as_t<Tgt, V> operator()(V v, as<Tgt> tgt) const noexcept
25 {
26 9573768 return POLYFLOAT_CALL(v, tgt);
27 }
28
29 template<concepts::real V, concepts::scalar_real Tgt>
30 9979245 POLYFLOAT_ABI constexpr eve::as_wide_as_t<Tgt, V> operator()(V v, as<Tgt> tgt) const noexcept
31 {
32 9979245 return POLYFLOAT_CALL(v, tgt);
33 }
34
35 template<concepts::simd_integral V, concepts::scalar_polyfloat Tgt>
36 4 POLYFLOAT_ABI constexpr eve::as_wide_as_t<Tgt, V> operator()(V v, as<Tgt> tgt) const noexcept
37 {
38 4 return POLYFLOAT_CALL(v, tgt);
39 }
40
41 96319298 POLYFLOAT_CALLABLE_OBJECT(convert_t, convert_);
42 };
43 //======================================================================================================================
44 //! @addtogroup core
45 //! @{
46 //! @var convert
47 //! @brief convert to a target type
48 //!
49 //! @groupheader{Header file}
50 //!
51 //! @code
52 //! #include <polyfloat/core.hpp>
53 //! @endcode
54 //!
55 //! @groupheader{Callable Signatures}
56 //!
57 //! @code
58 //! namespace polyfloat
59 //! {
60 //! template<eve::scalar_value U> constexpr auto convert(auto x, eve::as<U> ) noexcept;
61 //! }
62 //! @endcode
63 //!
64 //! **Parameter**
65 //! * `x`: polyfloat like value to process.
66 //!
67 //! **Template Parameter**
68 //! * `U`: target type to convert to.
69 //!
70 //! **Return value**
71 //!
72 //! The value resulting of the conversion of each of its elements to type U.
73 //!
74 //! @groupheader{Example}
75 //!
76 //! @godbolt{doc/core/convert.cpp}
77 //======================================================================================================================
78 inline constexpr auto convert = eve::functor<convert_t>;
79 //======================================================================================================================
80 //! @}
81 //======================================================================================================================
82 }
83
84 namespace plf::_
85 {
86 template<typename T, typename Z, eve::callable_options O>
87 96319298 constexpr auto convert_(POLYFLOAT_DELAY(), O const&, T const& v, as<Z>) noexcept
88 {
89 80752800 if constexpr (std::same_as<T, Z>) return v;
90 else if constexpr (concepts::polyfloat<Z>)
91 {
92 using type = eve::as_wide_as_t<Z, T>;
93 if constexpr (concepts::simd_integral<T>)
94 {
95 4 auto vr = eve::convert(v, eve::as<eve::underlying_type_t<Z>>());
96 4 return type{plf::convert(vr, eve::as<eve::element_type_t<Z>>{})};
97 }
98 9573794 else if constexpr (dimension_v<T> == 1ULL) return type{eve::convert(v, plf::as<plf::as_component_type_t<Z>>{})};
99 else
100 {
101 using u_t = as_component_type_t<Z>;
102 7235214 return kumi::apply([](auto const&... e) { return type{plf::convert(e, eve::as<u_t>{})...}; }, v);
103 }
104 }
105 1169224 else return eve::convert(v, eve::as<Z>{});
106 }
107 }
108