php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53204 IF Statement Long String
Submitted: 2010-10-29 22:50 UTC Modified: 2010-11-02 03:51 UTC
Votes:2
Avg. Score:3.0 ± 2.0
Reproduced:1 of 2 (50.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: diemuzi at gmail dot com Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 5.3.3 OS: Archlinux
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: diemuzi at gmail dot com
New email:
PHP Version: OS:

 

 [2010-10-29 22:50 UTC] diemuzi at gmail dot com
Description:
------------
I was testing long strings of numbers against an IF statement (see test) script and it was outputting information which was not true.

Test script:
---------------
This works:

$o = 33;
if ($o >= 29 && $o <= 32)
{
    echo "true";
} else {
    echo "false";
}

This does not work:

$o = 336571324099282374385465584513479344133;
if ($o >= 336571324099282374385465584513479344129 && $o <= 336571324099282374385465584513479344132)
{
    echo "true";
} else {
    echo "false";
}

Expected result:
----------------
In the working example, the output should be false. This is working as expected.

In the non-working example, the output should be false. However, it is returning true.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-10-30 23:04 UTC] phristen at yahoo dot com
PHP integers are 32 bit.
The actual value of $o is not what you think it is... Do this:
var_dump($o);
 [2010-11-02 03:51 UTC] aharvey@php.net
-Status: Open +Status: Bogus
 [2010-11-02 03:51 UTC] aharvey@php.net
As comment #1 indicates, this is due to the fact that you're actually dealing with floating point values, not integers.

Not a bug -> closing.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 19 12:01:30 2024 UTC