https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83800
Bug ID: 83800 Summary: [libquadmath] M_SQRT2q & sqrtq(2.0Q) off by one ULP ? Product: gcc Version: 7.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: sisyphus1 at optusnet dot com.au Target Milestone: --- Hi, Why does quadmath.h define M_SQRT2q to be 1.4142135623730950488016887242096981Q (0x1.6a09e667f3bcc908b2fb1366ea96p+0) when a closer approximation is 0x1.6a09e667f3bcc908b2fb1366ea95p+0 ? If I've calculated it correctly: 0x1.6a.....96p+0 exceeds sqrt(2) by approx 9.84e-35. 0x1.6a.....95p+0 falls short of sqrt(2) by approx 9.42e-35, and is therefore the nearest value. And 0x1.6a.....95p+0 is the value that the MPFR library returns for sqrt(2) for 113-bit precision, rounded to nearest. Is this a bug in gcc ? .... or are there mitigating factors to be considered ? Note also that sqrtq(2.0Q) returns the "wrong" value of 0x1.6a.....96p+0. In fact, it seems that sqrtq(x) returns a significand of 0x1.6a.....96p whenever x is a power of 2 that has an irrational square root. Cheers, Rob