On Wed, 26 Jan 2011 14:13:01 -0000, Daniel Convissor
<dani...@analysisandsolutions.com> wrote:
On Tue, Jan 25, 2011 at 04:15:26PM +0100, Pierre Joye wrote:
be sure to use the right type(s), do the casting correctly
Let's dial back the personalities for a moment. The issue raised above
produces bugs in DateTime::diff().
The existing code relies on C dropping decimal components when putting
float values into integers and the types passed to floor() and ceil().
This generally works on *nix machines, but throws Windows into a tizzy.
The following bugs seem to stem from these issues:
52798 dateTime => function diff => days KO
[...]
I can only speak for #52798, to which I attached a patch. There are
several problems, but the most serious one is that floor() is used without
the prototype available -- at least that's what the diagnostic message
Microsoft's compiler prints. Implicit declarations are not even allowed in
C99. But even if we admit the C89/90 implicit declaration returning int
(without prototype), this is problematic.
The actual prototype of floor() is
double floor(double x)
but it's called with a long long argument. If I'm not mistaken, the rules
for function calls without prototype are integer promotion (doesn't change
anything here because the rank of long long > rank of int) and float ->
double and therefore there is actually no conversion to double -- so
undefined behavior #1. Then we have that calling code expects an int, and
the functions returns a double -- undefined behavior #2.
However, the call to floor is not necessary because there's only integer
division, which still yields an integer. "Rounding" in integer division
doesn't exactly behave like floor because the first truncates towards zero
and the other one gives the largest integer not greater than the argument,
which differs for negative numbers. But the call to floor would still
would have no effect because floor() would already receive the result
truncated towards zero.
(there's still the problem that a double cannot represent without loss of
precision the same range of values as a long long)
--
Gustavo Lopes
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php