Fix powf overflow handling in non-nearest rounding mode
The threshold value at which powf overflows depends on the rounding mode and the current check did not take this into account. So when the result was rounded away from zero it could become infinity without setting errno to ERANGE. Example: pow(0x1.7ac7cp+5, 23) is 0x1.fffffep+127 + 0.1633ulp If the result goes above 0x1.fffffep+127 + 0.5ulp then errno is set, which is fine in nearest rounding mode, but powf(0x1.7ac7cp+5, 23) is inf in upward rounding mode powf(-0x1.7ac7cp+5, 23) is -inf in downward rounding mode and the previous implementation did not set errno in these cases. This special case is fixed without affecting the common code path by checking the rounding mode and using appropriate threshold value. Arithmetics is used to check the rounding mode to avoid introducing a stack frame when calling fegetround. Unfortunately the current test system does not support rounding modes. (Found by comparing against musl powf behaviour on the libc-test test suite, unfortunately that test system does not support errno.)
Loading
Please register or sign in to comment