Bug #64459 [Opn->Nab]: Wrong value on casting a float point number into int
| From: | aharvey@php.net | Date: | Tue, 19 Mar 2013 20:27:17 +0000 |
| Subject: | Bug #64459 [Opn->Nab]: Wrong value on casting a float point number into int | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-177912@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=64459&edit=1
ID: 64459
Updated by: aharvey@php.net
Reported by: marc-bennewitz at arcor dot de
Summary: Wrong value on casting a float point number into int
-Status: Open
+Status: Not a bug
Type: Bug
Package: Scripting Engine problem
Operating System: Linux acer-aspire-5680 3.2.0-38-
PHP Version: master-Git-2013-03-19 (Git)
Block user comment: N
Private report: N
New Comment:
Floating point values have a limited precision. Hence a value might
not have the same string representation after any processing. That also
includes writing a floating point value in your script and directly
printing it without any mathematical operations.
If you would like to know more about "floats" and what IEEE
754 is, read this:
http://www.floating-point-gui.de/
Thank you for your interest in PHP.
Previous Comments:
------------------------------------------------------------------------
[2013-03-19 20:18:38] marc-bennewitz at arcor dot de
Description:
------------
On some circumstances it's possible to get a wrong integer value on casting from float.
I can reproduce this bug with the following installations:
php -v
PHP 5.3.10-1ubuntu3.6 with Suhosin-Patch (cli) (built: Mar 11 2013 14:34:31)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies
with Xdebug v2.1.0, Copyright (c) 2002-2010, by Derick Rethans
./sapi/cli/php -v
PHP 5.6.0-dev (cli) (built: Mar 17 2013 22:02:54)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.6.0-dev, Copyright (c) 1998-2013 Zend Technologies
Test script:
---------------
// this works
$v = (float) 6;
var_dump($v, (int)$v);
// this is wrong
$v = log(64, 2);
var_dump($v, (int)$v);
Expected result:
----------------
float(6)
int(6)
float(6)
int(6)
Actual result:
--------------
float(6)
int(6)
float(6)
int(5)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=64459&edit=1