ID: 39622 Updated by: [EMAIL PROTECTED] Reported By: diefans at googlemail dot com -Status: Open +Status: Bogus Bug Type: Variables related Operating System: 2.6.8-2-686-smp GNU/Linux PHP Version: 5.2.0 New Comment:
Yes, it's clear and it's expected. Floats are expected to overflow when converted to int. Previous Comments: ------------------------------------------------------------------------ [2006-11-27 09:02:18] diefans at googlemail dot com its not that bogus - overflowing the values is normal (you don't have to teach me, you should better read, i want to help you fixing bugs...) what about the differences between version 5.2.0 and 5.1.4: PHP Version 5.1.4 decbin(-5850009183):10100011010011111111000110100001 shows at least the correct but truncated bits versus PHP version 5.2.0 decbin(-5850009183):10000000000000000000000000000000 which is quite wrong and not usable at all in terms of making bit-wise calculations like building certain checksums hope its clear what i mean.... ------------------------------------------------------------------------ [2006-11-24 21:02:26] [EMAIL PROTECTED] 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://docs.sun.com/source/806-3568/ncg_goldberg.html Thank you for your interest in PHP. ------------------------------------------------------------------------ [2006-11-24 17:25:13] diefans at googlemail dot com Description: ------------ php 5.2.0 prints the double values quite well in a string, but if you do calculations everything goes wrong Reproduce code: --------------- <?php /** * shows odd behavior with php version 5.2.0 * php version 5.1.4 seems to safe the bits */ $a = -5850009183; $aa = 2739925409; echo "\ngettype($a):".gettype($a); echo "\ngettype($aa):".gettype($aa); echo "\ndechex($a):".dechex($a); echo "\ndechex($aa):".dechex($aa); echo "\nhexdec(dechex($a)):".hexdec(dechex($a)); echo "\nhexdec(dechex($aa)):".hexdec(dechex($aa)); echo "\ndecbin($a):".decbin($a); echo "\ndecbin($aa):".decbin($aa); echo "\ndecoct($a):".decoct($a); echo "\ndecoct($aa):".decoct($aa); echo "\n"; ?> Expected result: ---------------- PHP 5.1.4 (cli) (built: Jul 17 2006 18:15:40): gettype(-5850009183):double gettype(2739925409):double dechex(-5850009183):a34ff1a1 dechex(2739925409):a34ff1a1 hexdec(dechex(-5850009183)):2739925409 hexdec(dechex(2739925409)):2739925409 decbin(-5850009183):10100011010011111111000110100001 decbin(2739925409):10100011010011111111000110100001 decoct(-5850009183):24323770641 decoct(2739925409):24323770641 Actual result: -------------- PHP 5.2.0 (cli) (built: Nov 19 2006 14:38:41): gettype(-5850009183):double gettype(2739925409):double dechex(-5850009183):80000000 dechex(2739925409):a34ff1a1 hexdec(dechex(-5850009183)):2147483648 hexdec(dechex(2739925409)):2739925409 decbin(-5850009183):10000000000000000000000000000000 decbin(2739925409):10100011010011111111000110100001 decoct(-5850009183):20000000000 decoct(2739925409):24323770641 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=39622&edit=1