在 2022/6/7 17:11, [email protected] 写道:
Attached is a patch to fix that.
The approach looks credible. However:The proposed solution transforms calculation of `pow(x, y)`, where `y` is negative, into `1 / pow(x, -y)`. This is not strictly equivalent. The maximum value that a `double` may represent is `0x1p+1023`, while the minimum positive (subnormal) value is `0x1p-1074`. Hence consider:
powi(2, -1025) = 0x1p-1025
but with the proposed implementation
powi(2, -1025) = 1 / powi(2, 1025)
= 1 / +infinity
= 0
which is apparently incorrect. My recommendation is that we do reciprocal first when `abs(x) > 1`,
but last if `abs(x) < 1`, so the absolute value of the multiplier is always < 1 and can't overflow.
Also please remove unreferenced variables:
test.c: In function ‘powi’:
test.c:8:15: warning: unused variable ‘rslt’ [-Wunused-variable]
8 | double d, rslt;
| ^~~~
test.c:8:12: warning: variable ‘d’ set but not used
[-Wunused-but-set-variable]
8 | double d, rslt;
| ^
test.c:7:9: warning: unused variable ‘odd_y’ [-Wunused-variable]
7 | int odd_y = y & 1;
| ^~~~~
--
Best regards,
LIU Hao
OpenPGP_signature
Description: OpenPGP digital signature
_______________________________________________ Mingw-w64-public mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
