php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48867 Casting 0xffffffffffffffff to int does not return -1
Submitted: 2009-07-09 11:40 UTC Modified: 2016-12-14 17:22 UTC
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (50.0%)
From: magicaltux@php.net Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.2.10 OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: magicaltux@php.net
New email:
PHP Version: OS:

 

 [2009-07-09 11:40 UTC] magicaltux@php.net
Description:
------------
Casting hexadecimal representation of -1 to int is supposed to return -1 in php.

It seems to not reproduce on sunOS.

<dsp_> sapi/cli/php -r 'var_dump((int)0xffffffffffffffff);'
<dsp_> int(-1)
<dsp_> SunOS t2000-010131 5.11 snv_101 sun4v sparc SUNW,Sun-Fire-T200 Solaris

It was reproduced on the following distro of Linux: Gentoo, Arch

It was also reproduced on a self-compiled version of PHP 5.2.10

Reproduce code:
---------------
magicaltux@Memol ~ $ php -r 'var_dump((int)0xffffffffffffffff);'


Expected result:
----------------
int(-1)

Actual result:
--------------
int(0)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-07-09 11:44 UTC] magicaltux@php.net
uname -a of test machines:

Linux Memol.ooKoo.org 2.6.28-gentoo-r3-tux #1 SMP Thu Mar 12 22:09:11 CET 2009 x86_64 Intel(R) Core(TM) i7 CPU 920 @ 2.67GHz GenuineIntel GNU/Linux

Linux localhost 2.6.30-gentoo-r1 #1 SMP Tue Jun 30 14:06:51 Local time zone must be set--see zic  x86_64 Intel(R) Core(TM)2 Quad CPU Q9550 @ 2.83GHz GenuineIntel GNU/Linux

 [2009-07-09 11:45 UTC] c dot robin at smartphp dot org
Reproduced on ArchLinux ( both compiled package and custom compiled PHP with no patches ).
Uname:
Linux devrobin 2.6.30-ARCH #1 SMP PREEMPT Sat Jul 4 02:24:43 CEST 2009 x86_64 Intel(R) Core(TM)2 Duo CPU E7200 @ 2.53GHz GenuineIntel GNU/Linux
 [2009-07-09 11:51 UTC] magicaltux@php.net
Reproduced on 5.2.9:

Kaze ~ # php -v
PHP 5.2.9-pl2-gentoo (cli) (built: May 11 2009 19:07:50) (DEBUG)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies
Kaze ~ # php -r 'var_dump((int)0xffffffffffffffff);'
int(0)
Kaze ~ # uname -a
Linux Kaze 2.6.29-gentoo-tux #1 SMP PREEMPT Fri Apr 17 00:36:53 CEST 2009 x86_64 Intel(R) Core(TM)2 CPU U7500 @ 1.06GHz GenuineIntel GNU/Linux

 [2009-08-01 11:09 UTC] kalle@php.net
This is also cast to 0 on Windows:
C:\php\src>uname
Windows NT SANDIE 6.0 build 6001 (Windows Vista Ultimate Edition Service Pack 1) i586
 [2016-12-14 17:22 UTC] leigh@php.net
-Status: Open +Status: Not a bug
 [2016-12-14 17:22 UTC] leigh@php.net
IEEE 754 rounding issue.

The int literal is auto-promoted to float, and due to the loss of precision it really does wrap to 0 when cast back to int
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 10:01:28 2024 UTC