GCC Code Coverage Report


Directory: include/polyfloat/
File: include/polyfloat/module/core/sqrt.hpp
Date: 2026-11-09 15:28:50
Exec Total Coverage
Lines: 5 5 100.0%
Functions: 54 54 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/rsqrt.hpp>
15 #include <polyfloat/module/core/is_eqz.hpp>
16 #include <polyfloat/module/core/is_pinf.hpp>
17 #include <polyfloat/module/core/is_nan.hpp>
18
19 namespace plf
20 {
21
22 template<typename Options> struct sqrt_t : eve::callable<sqrt_t, Options, raw_option, pedantic_option>
23 {
24 41328 template<concepts::polyfloat_like Z> POLYFLOAT_ABI constexpr Z operator()(Z z) const noexcept
25 {
26 41328 return POLYFLOAT_CALL(z);
27 }
28
29 41328 POLYFLOAT_CALLABLE_OBJECT(sqrt_t, sqrt_);
30 };
31 //======================================================================================================================
32 //! @addtogroup core
33 //! @{
34 //! @var sqrt
35 //! @brief return the square root value.
36 //!
37 //! @groupheader{Header file}
38 //!
39 //! @code
40 //! #include <polyfloat/core.hpp>
41 //! @endcode
42 //!
43 //! @groupheader{Callable Signatures}
44 //!
45 //! @code
46 //! namespace polyfloat
47 //! {
48 //! template<polyfloat::concepts::polyfloat_like T> constexpr auto sqrt(T z) noexcept;
49 //! template<polyfloat::concepts::polyfloat_like T> constexpr auto sqrt[raw](T z) noexcept;
50 //! }
51 //! @endcode
52 //!
53 //! **Parameters**
54 //!
55 //! * `z`: Value to process.
56 //!
57 //! **Return value**
58 //!
59 //! Returns the square root of z. With raw option the computation can overflow.
60 //!
61 //! @groupheader{Example}
62 //!
63 //! @godbolt{doc/core/sqrt.cpp}
64 //======================================================================================================================
65
66 inline constexpr auto sqrt = eve::functor<sqrt_t>;
67 //======================================================================================================================
68 //! @}
69 //======================================================================================================================
70 }
71
72 namespace plf::_
73 {
74
75 41328 template<typename Z, eve::callable_options O> constexpr auto sqrt_(POLYFLOAT_DELAY(), O const& o, Z const& z) noexcept
76 {
77 41328 return if_else(plf::is_eqz(z) || plf::is_pinf(z), z, plf::rsqrt[o](z) * z);
78 }
79 }
80