On Sun, 04 Mar 2012 14:29:49 +0100, Anthony Ferrara <ircmax...@gmail.com> wrote:

I had messaged about these patches before, but with the 5.4 release
process happening I think it slipped through the cracks.  I have 3
patches that are ready for inclusion...
[...]

https://bugs.php.net/bug.php?id=60789
Bringing pow() inline with docs in that it will attempt to return an
integer (by casting one or more of the arguments to int) if possible.
This fixes a precision loss that can occur with float arguments that
are exactly integers on 64 bit platforms.

[...]

This doesn't seem right. It's overly clever. It's like saying that

4.0 + 1

should return int(5) and not float(5.). Or perhaps a closer analogy would be:

if we're in a 64-bit platform (only then can integers have a larger precision than doubles);
if one of the operands is exactly an integer;
if the other operand is a float exactly representable as an integer (perhaps a large power of 2), but its accuracy is negative (where accuracy is the 15.9546 - log10(abs(x)), or, informally, the effective number of digits to the right of the decimal point);
if the result of the sum is exactly representable as a 64-bit integer;
then return such integer.

It's easy to see these sort of tricks would have to be applied all over the place (additions, products, and all other mathematical operations).

In sum, I think the rule that if a mathematical operation involves a float, the result should be a float ought to be kept.

--
Gustavo Lopes

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to