@@ -47,14 +47,16 @@ inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2>::type hypot(_A1 __x, _
47
47
}
48
48
49
49
#if _LIBCPP_STD_VER >= 17
50
+ // Factors needed to determine if over-/underflow might happen for `std::hypot(x,y,z)`.
50
51
template <class _Real >
51
52
struct __hypot_factors {
52
53
_Real __threshold;
53
54
_Real __scale_xyz;
54
55
_Real __scale_M;
55
56
};
56
57
57
- // returns [underflow_factors, overflow_factors]
58
+ // Computes `__hypot_factors` needed to determine if over-/underflow might happen for `std::hypot(x,y,z)`.
59
+ // Returns: [underflow_factors, overflow_factors]
58
60
template <class _Real >
59
61
_LIBCPP_HIDE_FROM_ABI std::array<__math::__hypot_factors<_Real>, 2 > __create_factors () {
60
62
static_assert (std::numeric_limits<_Real>::is_iec559);
@@ -84,6 +86,10 @@ _LIBCPP_HIDE_FROM_ABI std::array<__math::__hypot_factors<_Real>, 2> __create_fac
84
86
return {__underflow, __overflow};
85
87
}
86
88
89
+ // Computes the three-dimensional hypotenuse: `std::hypot(x,y,z)`.
90
+ // The naive implementation might over-/underflow which is why this implementation is more involved:
91
+ // If the square of an argument might run into issues, we scale the arguments appropriately.
92
+ // See https://github.com/llvm/llvm-project/issues/92782 for a detailed discussion and summary.
87
93
template <class _Real >
88
94
_LIBCPP_HIDE_FROM_ABI _Real __hypot (_Real __x, _Real __y, _Real __z) {
89
95
const auto [__underflow, __overflow] = __math::__create_factors<_Real>();
0 commit comments