php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #53852 Bug with conversation from float
Submitted: 2011-01-27 11:33 UTC Modified: 2011-01-28 00:38 UTC
From: dohardgopro at gmail dot com Assigned:
Status: Not a bug Package: Variables related
PHP Version: 5.2.17 OS: Freebsd AMD64
Private report: No CVE-ID: None
 [2011-01-27 11:33 UTC] dohardgopro at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/language.types.float
---


Test script:
---------------
var_dump((int)((float)4043529379404059246));
Output:
4043529379404059136
Expected:
4043529379404059246


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-01-27 11:53 UTC] rquadling@php.net
You should count yourself lucky! At least your conversion is in the ballpark.

On my 32bit windows ...

php -r "var_dump((int)((float)4043529379404059246));" 381D808C0A3C126E
int(171708928) A3C1200

The hex values shows something interesting.

4043529379404059246 = 0x381D808C0A3C126E
171708928           = 0x000000000A3C1200
4043529379404059136 = 0x381D808C0A3C1200

So, the 32bit truncation is sort of expected, but the chopping of the lower 8 
bits isn't.
 [2011-01-27 15:53 UTC] dohardgopro at gmail dot com
-Operating System: Freebsd +Operating System: Freebsd AMD64
 [2011-01-27 15:53 UTC] dohardgopro at gmail dot com
Add architecture
 [2011-01-27 15:58 UTC] dohardgopro at gmail dot com
On my 32bit debian system:

php -r "var_dump((int)((float)4043529379404059246));"
int(171708928)

I think it because of difference between int size on 32bit systems and 64bit 
systems
PHP_INT_MAX int 32bit systems = 2147483647
PHP_INT_MAX int 64bit systems = 9223372036854775807
 [2011-01-28 00:38 UTC] aharvey@php.net
-Status: Open +Status: Bogus
 [2011-01-28 00:38 UTC] aharvey@php.net
4043529379404059246 is well past the point where a double precision
float can represent an integer exactly (2^53, from memory): ergo, some
data loss is inevitable at that point.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Apr 28 21:01:29 2024 UTC