## Re: [Mingw-users] [Mingw-w64-public] Math library discrepancies that surprised me.

 Re: [Mingw-users] [Mingw-w64-public] Math library discrepancies that surprised me. From: JonY - 2011-05-03 01:24:31 Attachments: signature.asc 0xED74C077.asc ```On 5/3/2011 04:05, Kai Tietz wrote: > 2011/5/2 Peter Rockett : >> On 02/05/2011 17:00, Keith Marshall wrote: >>> On 02/05/11 16:30, Charles Wilson wrote: >>>>> So, we would like sqrt (x) and pow (x, 0.5) to agree. >> >> The point below about off-topic diversions into precision is valid but >> can I reiterate, there is no good reason why x^(0.5) calculated two >> different ways should agree since the two different routes will >> accumulate different rounding errors. Adding a special case to force >> agreement for x^n when n = 0.5 will introduce a discontinuity into the >> pow() function and is a very bad idea. The value of returned by pow(x, >> 0.5) might be less accurate compared to sqrt(x) but that is part of the >> fundamental issue with using floating-point numbers: they are only ever >> approximations. You have to take that fact on board. > > Correct, the ways of calculation of pow (x, 0.5) and sqrt (x) are different. > Nevertheless is it an issue in gcc. As if you are writing pow (1.1, > 0.5) or sqrt (1.1) - which means gcc optimize it via gmp to a > precalculated result - it has identical values. But by using > math-library results in a - expectable - difference in result. > So IMHO pow should special case here to provide same result as pow > does for y = 0.5. I would agree with the others that its a horrible hack to treat "0.5" special, I don't remember reading anything about requiring pow() results to agree with sqrt(). Can we at least follow a standard spec like: ; We can remove the special case, right? ```