From:             php at lipfi dot ch
Operating system: Gentoo Linux 2005.1
PHP version:      5.1.1
PHP Bug Type:     Scripting Engine problem
Bug description:  Strange behaviour when multiplying floats with one 
multiplicator being 0

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 bug report at http://bugs.php.net/?id=35656&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=35656&r=trysnapshot44
Try a CVS snapshot (PHP 5.1): 
http://bugs.php.net/fix.php?id=35656&r=trysnapshot51
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=35656&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=35656&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=35656&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=35656&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=35656&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=35656&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=35656&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=35656&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=35656&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=35656&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=35656&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=35656&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=35656&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=35656&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=35656&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=35656&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=35656&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=35656&r=mysqlcfg

Reply via email to