OSDN Git Service

math: rewrite hypot
authorSzabolcs Nagy <nsz@port70.net>
Tue, 3 Sep 2013 14:37:48 +0000 (14:37 +0000)
committerSzabolcs Nagy <nsz@port70.net>
Thu, 5 Sep 2013 11:30:07 +0000 (11:30 +0000)
commitc2a0dfea629617a39af2f59bd400e1a3595d0783
treed0401b88980dba72d3c2dc21cf6a11642828a51b
parentee2ee92d62c43f6658d37ddea4c316d2089d0fe9
math: rewrite hypot

method: if there is a large difference between the scale of x and y
then the larger magnitude dominates, otherwise reduce x,y so the
argument of sqrt (x*x+y*y) does not overflow or underflow and calculate
the argument precisely using exact multiplication. If the argument
has less error than 1/sqrt(2) ~ 0.7 ulp, then the result has less error
than 1 ulp in nearest rounding mode.

the original fdlibm method was the same, except it used bit hacks
instead of dekker-veltkamp algorithm, which is problematic for long
double where different representations are supported. (the new hypot
and hypotl code should be smaller and faster on 32bit cpu archs with
fast fpu), the new code behaves differently in non-nearest rounding,
but the error should be still less than 2ulps.

ld80 and ld128 are supported
src/math/hypot.c
src/math/hypotf.c
src/math/hypotl.c