Bug #12505 Updated: array_sum function total calculate error

From: Date: Wed, 01 Aug 2001 09:56:08 +0000
Subject: Bug #12505 Updated: array_sum function total calculate error
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-61737@lists.php.net to get a copy of this message
ID: 12505
Updated by: jmcastagnetto
Reported By: omeroz@kamilkoc.com.tr
Status: Open
Bug Type: Arrays related
Old Operating System: Red Hat Linux 7.1
Operating System: Red Hat Linux 6.1
Old PHP Version: 4.0.4pl1
PHP Version: latest CVS (08/01/01)
New Comment:

The problem is with the typecasting to LONG, if you use the code:

<?php
$tt=array(382478633.0,367687181.0,452504275.0,471367521.0,848270658.0,1181944543.0);
echo array_sum($tt)."\n";
?>

The result is the correct one (3704252811)

Solution would be to

1) use floating point representation for bign numbers in PHP code (add caveat to the manual
perhaps?)

or

2) check that the array_sum result is nor overflowing LONG in the C code implementation and bump the
type to DOUBLE if it does.

second option would be better IMHO

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

[2001-08-01 04:02:52] omeroz@kamilkoc.com.tr

$tt=array(382478633,367687181,452504275,471367521,848270658,1181944543);
$total_tt=array_sum($tt);
echo "Total_tt=".$total_tt;

// Prints  Total_tt=-590714485

Must be 3704252811.




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



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



Thread (7 messages)

« previous php.dev (#61737) next »