Doc #53852 [Opn->Bgs]: Bug with conversation from float

From: Date: Thu, 27 Jan 2011 23:38:54 +0000
Subject: Doc #53852 [Opn->Bgs]: Bug with conversation from float
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-5884@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=53852&edit=1 ID: 53852 Updated by: aharvey@php.net Reported by: dohardgopro at gmail dot com Summary: Bug with conversation from float -Status: Open +Status: Bogus Type: Documentation Problem Package: Variables related Operating System: Freebsd AMD64 PHP Version: 5.2.17 Block user comment: N Private report: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2011-01-27 15:58:03] 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-27 15:53:24] dohardgopro at gmail dot com Add architecture ------------------------------------------------------------------------ [2011-01-27 11:53:11] 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 11:33:22] 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 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=53852&edit=1

« previous php.doc.bugs (#5884) next »