hypotl(LDBL_MAX, 0.0L) = inf

Corinna Vinschen corinna-cygwin@cygwin.com
Mon Apr 19 11:02:57 GMT 2021


On Apr 17 10:02, airplanemath via Cygwin wrote:
> Given that hypot(DBL_MAX, 0.0) = DBL_MAX and hypotf(FLT_MAX, 0.0f) =
> FLT_MAX, I suspect this is a problem in hypotl.  Am I missing something?

No.  This is a bug in newlib's hypotl.  Newlib mainly targest embedded
systems and as such wasn't very much interested in long double arithmetic
for a long time.

In contrast to hypot and hypotf, it's not implemented as exact function,
but just as the outside idea sqrtl (x^2 + y^2).  With LDBL_MAX ^ 2 ==
inf as input, sqrtl returns inf.  So what we get here is an intermediate
overflow, that wouldn't occur if the hypotl function would be implemented
in detail.

The problem is, somebody would have to do it.  That is, implementing
a hypotl which works for all supported CPU types.  There are quite a few
long double variations in the wild, unfortunately...

Having said that, there's an easier way out for Cygwin: We just use
the hypotl function from Mingw-w64 for Cygwin as well.

I pushed this patch and uploaded new developer snapshots to
https://cygwin/snapshots/

Please give it a try.


Thanks,
Corinna


More information about the Cygwin mailing list