[libcxx-commits] [libcxx] [libc++][math] Fix undue overflowing of `std::hypot(x, y, z)` (PR #93350)
via libcxx-commits
libcxx-commits at lists.llvm.org
Sun Jul 7 06:05:36 PDT 2024
================
@@ -41,6 +46,89 @@ inline _LIBCPP_HIDE_FROM_ABI typename __promote<_A1, _A2>::type hypot(_A1 __x, _
return __math::hypot((__result_type)__x, (__result_type)__y);
}
+#if _LIBCPP_STD_VER >= 17
+// Factors needed to determine if over-/underflow might happen for `std::hypot(x,y,z)`.
+template <class _Real>
+struct __hypot_factors {
+ _Real __threshold;
+ _Real __scale_xyz;
+ _Real __scale_M;
+};
+
+// Computes `__hypot_factors` needed to determine if over-/underflow might happen for `std::hypot(x,y,z)`.
+// Returns: [underflow_factors, overflow_factors]
+template <class _Real>
+_LIBCPP_HIDE_FROM_ABI array<__math::__hypot_factors<_Real>, 2> __create_factors() {
----------------
PaulXiCao wrote:
To get rid of the `std::array` usage I refactored the implementation of `__hypot`. Now there is no more `hypot_factors` struct nor this `create()` function. Only one function returning the `overflow_threshold` and its respective `overflow_scaling` factor.
https://github.com/llvm/llvm-project/pull/93350
More information about the libcxx-commits
mailing list