php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39622 overflow on double word
Submitted: 2006-11-24 17:25 UTC Modified: 2006-11-27 10:16 UTC
From: diefans at googlemail dot com Assigned:
Status: Not a bug Package: Variables related
PHP Version: 5.2.0 OS: 2.6.8-2-686-smp GNU/Linux
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: diefans at googlemail dot com
New email:
PHP Version: OS:

 

 [2006-11-24 17:25 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-11-24 21:02 UTC] tony2001@php.net
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-27 09:02 UTC] 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-27 10:16 UTC] tony2001@php.net
Yes, it's clear and it's expected.
Floats are expected to overflow when converted to int.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Nov 03 05:01:28 2024 UTC