Edit report at http://bugs.php.net/bug.php?id=53045&edit=1
ID: 53045
User updated by: remy at wh dot nl
Reported by: remy at wh dot nl
Summary: broken result of intval()
Status: Open
Type: Bug
Package: *Math Functions
Operating System: FreeBSD
PHP Version: 5.2.14
Block user comment: N
New Comment:
Yes, 32bit, here is some hardware and OS info from sysctl:
kern.ostype: FreeBSD
kern.osrelease: 7.3-STABLE
kern.osrevision: 199506
kern.version: FreeBSD 7.3-STABLE #7: Thu Jul 15 20:09:49 CEST 2010
kern.maxvnodes: 100000
kern.maxproc: 6164
kern.maxfiles: 12328
kern.argmax: 262144
kern.securelevel: -1
kern.clockrate: { hz = 1000, tick = 1000, profhz = 2000, stathz = 133 }
kern.posix1version: 200112
kern.ngroups: 16
kern.job_control: 1
kern.saved_ids: 0
kern.boottime: { sec = 1281862574, usec = 963320 } Sun Aug 15 10:56:14
2010
kern.domainname:
kern.osreldate: 703100
kern.bootfile: /boot/kernel/kernel
kern.maxfilesperproc: 11095
kern.maxprocperuid: 5547
hw.machine: i386
hw.model: Intel(R) Pentium(R) 4 CPU 3.20GHz
hw.ncpu: 2
hw.byteorder: 1234
hw.physmem: 2134020096
hw.usermem: 1906421760
hw.pagesize: 4096
hw.floatingpoint: 1
hw.machine_arch: i386
hw.realmem: 2147155968
Previous Comments:
------------------------------------------------------------------------
[2010-10-12 19:06:39] [email protected]
Only a problem on 32-bit systems I assume? I can't reproduce it here,
but all my
stuff is 64-bit.
------------------------------------------------------------------------
[2010-10-12 18:34:15] remy at wh dot nl
Description:
------------
intval(log(8,2)) gives 2 as result, expected 3
Test script:
---------------
<?php
$maxrounds = log(8, 2);
echo 'test:'.$maxrounds."\n";
echo 'test:'.log(8,2)."\n";
echo 'intval:'.intval(3.0000)."\n";
echo 'intval:'.intval(log(8,2))."\n";
echo 'intval:'.intval($maxrounds)."\n";
echo 'intval+1:'.(intval($maxrounds)+1)."\n";
echo 'intval+1:'.intval($maxrounds+1)."\n";
echo 'intval+1:'.intval($maxrounds + 1)."\n";
echo 'sprintf dec:'.sprintf('%d', $maxrounds)."\n";
echo 'sprintf float:'.sprintf('%f', $maxrounds)."\n";
echo 'sprintf float non-locale:'.sprintf('%F', $maxrounds)."\n";
var_dump($maxrounds)."\n";
?>
Expected result:
----------------
test:3
test:3
intval:3
intval:3
intval:3
intval+1:4
intval+1:4
intval+1:4
sprintf dec:3
sprintf float:3.000000
sprintf float non-locale:3.000000
float(3)
Actual result:
--------------
test:3
test:3
intval:3
intval:2
intval:2
intval+1:3
intval+1:3
intval+1:3
sprintf dec:2
sprintf float:3.000000
sprintf float non-locale:3.000000
float(3)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=53045&edit=1