#35656 [Opn->Bgs]: Strange behaviour when multiplying floats with one multiplicator being 0

From: Date: Tue, 13 Dec 2005 10:02:54 +0000
Subject: #35656 [Opn->Bgs]: Strange behaviour when multiplying floats with one multiplicator being 0
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-90340@lists.php.net to get a copy of this message
 ID:               35656
 Updated by:       sniper@php.net
 Reported By:      php at lipfi dot ch
-Status:           Open
+Status:           Bogus
 Bug Type:         Scripting Engine problem
 Operating System: Gentoo Linux 2005.1
 PHP Version:      5.1.1
 New Comment:

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




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

[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


Thread (4 messages)

« previous php.bugs (#90340) next »