PHP 4.0 Bug #6034: Simple Addition not correct

From: Date: Wed, 09 Aug 2000 04:01:00 +0000
Subject: PHP 4.0 Bug #6034: Simple Addition not correct
Groups: php.dev 
Request: Send a blank email to php-dev+get-28201@lists.php.net to get a copy of this message
From: markn@alverstone.com.au Operating system: Linux, Windows + ? PHP version: 4.0.1pl2 PHP Bug Type: Scripting Engine problem Bug description: Simple Addition not correct When adding several numbers it appears that they should add to zero. Unfortunatly they dont. For example: <? // This is a very simple representation of the problem $ary[] = 54493.08; $ary[] = 18900.58; $ary[] = 45819.39; $ary[] = 22901.79; $ary[] = 13342.42; $ary[] = -127799; $ary[] = 1755; $ary[] = -29413.01; $ary[] = -0.25; $ary[] = 0; while(list($key,$val) = each($ary)){ $total = $val + $total; echo "Value: $val Total: $total<br>\n"; } ?> The running total returns; Value: 54493.08 Total: 54493.08 Value: 18900.58 Total: 73393.66 Value: 45819.39 Total: 119213.05 Value: 22901.79 Total: 142114.84 Value: 13342.42 Total: 155457.26 Value: -127799 Total: 27658.26 Value: 1755 Total: 29413.26 Value: -29413.01 Total: 0.25000000001091 Value: -0.25 Total: 1.0913936421275E-011 Value: 0 Total: 1.0913936421275E-011 So you can see that 29413.26 + -29413.01 doesnt equal 0.25 as it should. mn

« previous php.dev (#28201) next »