[PATCH] Returns NaN for sqrt with negative fp argument

Joerg Sonnenberger joerg at britannica.bec.de
Wed Jun 11 06:16:17 PDT 2014

On Tue, Jun 10, 2014 at 07:17:30AM +0100, Tim Northover wrote:
> > Also, sqrt in glibc behaves like this, and clang is defining __GNUC__, so it
> > means we need to keep compatibility with GCC around this as well.
> I don't find that compelling, either. Particularly when -ffast-math is
> involved, we shouldn't be expected to replicate the precise points
> where GCC decides to ignore NaNs and how it does so.

Let me try to summarize the specs:

(1) sqrt for negative input should return qNaN for IEE conformance.
(2) For -ffast-math, negative input is undefined.

For me it seems more consistent to return the correct value (qNaN) if
there is no penalty for choosing it. Is there any performance advantage
of using the explicitly incorrect 0.0?


More information about the llvm-commits mailing list