ID:               35656
 User updated by:  php at lipfi dot ch
 Reported By:      php at lipfi dot ch
 Status:           Bogus
 Bug Type:         Scripting Engine problem
 Operating System: Gentoo Linux 2005.1
 PHP Version:      5.1.1
 New Comment:

I fear your decision to mark this as bogus was a very quick one. 

http://www.php.net/manual/en/language.operators.arithmetic.php

does not tell me anywhere that the commutative law is not valid in PHP.


Also note that I'm very well aware of floats having limited precision,
but -0 is no defined value and certainly not something you'd expect to
get as a result of a multiplication. And certainly not depending on the
operands order.

0*0.02 = -0
0.02*0 = 0

where var_dump() certainly knows that -0 == 0, but the engines core
seems not to.

I certainly expect the arithmetics in PHP to work like it's supposed
to. This means adhering to the commutative law which basically means
that I can interchange the operands in a multiplication.

Besides: -0 is IMHO not a valid value. It's either 0 or not 0, but not
-0.

I'd really appreciate a further comment of why the behaviour whitnessed
here is really working as intended and where that is documented in the
manual.

Thank you

Philip


Previous Comments:
------------------------------------------------------------------------

[2005-12-13 11:02:53] [EMAIL PROTECTED]

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php



------------------------------------------------------------------------

[2005-12-13 11:00:33] php at lipfi dot ch

Description:
------------
When multiplying two float values, one being 0, one being negative,
it's possible to either get 0 or -0 (!) as a result depending on the
operands order.

This is IMHO not how math is supposed to work.

Additionally, I'm seing discrepancies between the variables value and
what var_dump() things it contains. The problem is very simple to
reproduce

Reproduce code:
---------------
<?php
  $v = 0*-0.02;
  var_dump($v);
  echo "$v\n";
  $v = floatval($v);
  echo "$v\n\n";

  $v = -0.02*0;
  var_dump($v);
  echo "$v\n";
?>

Expected result:
----------------
float(0)
0
0

float(0)
0

Actual result:
--------------
float(0)
-0
-0

float(0)
0

(the -0 obviously being the problem here)


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=35656&edit=1

Reply via email to