Skip to content

Commit 458b0d3

Browse files
committed
document non-naive implementation
1 parent 912833e commit 458b0d3

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

libcxx/include/__math/hypot.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,16 @@ inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2>::type hypot(_A1 __x, _
4747
}
4848

4949
#if _LIBCPP_STD_VER >= 17
50+
// Factors needed to determine if over-/underflow might happen for `std::hypot(x,y,z)`.
5051
template <class _Real>
5152
struct __hypot_factors {
5253
_Real __threshold;
5354
_Real __scale_xyz;
5455
_Real __scale_M;
5556
};
5657

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]
5860
template <class _Real>
5961
_LIBCPP_HIDE_FROM_ABI std::array<__math::__hypot_factors<_Real>, 2> __create_factors() {
6062
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
8486
return {__underflow, __overflow};
8587
}
8688

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.
8793
template <class _Real>
8894
_LIBCPP_HIDE_FROM_ABI _Real __hypot(_Real __x, _Real __y, _Real __z) {
8995
const auto [__underflow, __overflow] = __math::__create_factors<_Real>();

0 commit comments

Comments
 (0)