[libcxx-commits] [libcxx] [libc++][math] Fix undue overflowing of `std::hypot(x, y, z)` (PR #93350)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Jul 4 12:14:48 PDT 2024
================
@@ -9,11 +9,16 @@
#ifndef _LIBCPP___MATH_HYPOT_H
#define _LIBCPP___MATH_HYPOT_H
+#include <__algorithm/max.h>
#include <__config>
+#include <__math/abs.h>
+#include <__math/roots.h>
#include <__type_traits/enable_if.h>
#include <__type_traits/is_arithmetic.h>
#include <__type_traits/is_same.h>
#include <__type_traits/promote.h>
+#include <array>
----------------
ldionne wrote:
Sorry for not spotting this earlier, but I would like to avoid including `<array>` here. This is a low-level math function and we should avoid pulling in `<array>`, which then pulls in a ton of additional stuff (like some algorithms we totally don't need here).
It's kinda hacky, but we could just define our own `__hypot_factors_pair` type as a struct with two members instead.
@philnik777 WDYT about introducing something like this to break dependencies for internal uses only (not as part of this patch though)?
```c++
template <class _Tp, class _Up>
struct __basic_pair {
[[no_unique_address]] _Tp __first;
[[no_unique_address]] _Up __second;
};
```
https://github.com/llvm/llvm-project/pull/93350
More information about the libcxx-commits
mailing list