[libc-commits] [PATCH] D118157: [libc] Improve hypotf performance with different algorithm correctly rounded to all rounding modes.

Vincent Lefèvre via Phabricator via libc-commits libc-commits at lists.llvm.org
Wed Jan 26 06:36:34 PST 2022


vinc17 added inline comments.


================
Comment at: libc/src/math/generic/hypotf.cpp:29-30
+  // Compute the rounding error with Dekker's algorithm.
+  double err = ((sumSq - xSq) - ySq) + ((sumSq - ySq) - xSq);
+
+  // Take sqrt in double precision.
----------------
zimmermann6 wrote:
> I hadn't seen that trick to compute the rounding error, do you have a reference?
> By the way, I'm not sure the reference to Dekker is appropriate. For me, Dekker's algorithm splits
> two floating-point numbers in two each, and computes their product (high + low part) using 4 multiplies.
If I understand correctly, `err` should get the rounding error of the sum. The algorithm is known as TwoSum. It needs 6 operations, including the sum `sumSq`, and this is the same number of operations as you have. But with 6 add/sub operations, I proved that there is only one algorithm (up to obvious symmetries) that works. And the above one is different. Thus it will be sometimes incorrect. I think that if `xSq` and `ySq` are close to each other and their sum is not exact, then the above algorithm will give you twice the rounding error.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D118157/new/

https://reviews.llvm.org/D118157



More information about the libc-commits mailing list