[PATCH] Define 3-argument overloads of std::hypot for C++17 (P0030R1)
Marc Glisse
marc.glisse@inria.fr
Tue Sep 27 21:50:00 GMT 2016
On Tue, 27 Sep 2016, Jonathan Wakely wrote:
> This adds the new 3D std::hypot() functions. This implementation seems
> to be faster than the naïve sqrt(x*x + y*y + z*z) implementation, or
> hypot(hypot(x, y), z), and should be a bit more accurate at very large
> or very small values due to reducing the arguments by the largest one.
> Improvements welcome though, as this is not my forte.
I understand the claims about accuracy, but the one about speed seems very
surprising to me. Was your test specifically with denormals on
not-so-recent hardware, or specifically when sqrt does a library call for
errno? Otherwise, I have a hard time believing that 3 multiplications and
2 additions can be slower than 4 multiplications, 2 additions, plus a
bunch of tests and divisions.
--
Marc Glisse
More information about the Libstdc++
mailing list