php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53222 "less than" operator returning true even if numbers are equal
Submitted: 2010-11-02 02:06 UTC Modified: 2010-11-02 02:33 UTC
From: viliam dot kubis at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.3.3 OS: fedora 13
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: viliam dot kubis at gmail dot com
New email:
PHP Version: OS:

 

 [2010-11-02 02:06 UTC] viliam dot kubis at gmail dot com
Description:
------------
I am using the following PHP version:

PHP 5.3.3 (cli) (built: Jul 22 2010 15:57:00) 

Info: re-typing everything to (float), (double) or "no type specified" does not fix the problem.

Test script:
---------------
<? 
$min=(float)44;
$max=(float)54545;

$step=(float)($max-$min)/10;

if($step && $step>0)
{
	$i=$min;
	while($i<$max)
	{
		echo($i." &lt; $max ");
		var_dump($i,$max,$step);
		echo("<br />");
		$i+=$step;
	}
}
if($i>$max) echo("WHAT?");  ?> 

Expected result:
----------------
44 < 54545 float(44) float(54545) float(5450.1) 
5494.1 < 54545 float(5494.1) float(54545) float(5450.1) 
10944.2 < 54545 float(10944.2) float(54545) float(5450.1) 
16394.3 < 54545 float(16394.3) float(54545) float(5450.1) 
21844.4 < 54545 float(21844.4) float(54545) float(5450.1) 
27294.5 < 54545 float(27294.5) float(54545) float(5450.1) 
32744.6 < 54545 float(32744.6) float(54545) float(5450.1) 
38194.7 < 54545 float(38194.7) float(54545) float(5450.1) 
43644.8 < 54545 float(43644.8) float(54545) float(5450.1) 
49094.9 < 54545 float(49094.9) float(54545) float(5450.1) 


Actual result:
--------------
44 < 54545 float(44) float(54545) float(5450.1) 
5494.1 < 54545 float(5494.1) float(54545) float(5450.1) 
10944.2 < 54545 float(10944.2) float(54545) float(5450.1) 
16394.3 < 54545 float(16394.3) float(54545) float(5450.1) 
21844.4 < 54545 float(21844.4) float(54545) float(5450.1) 
27294.5 < 54545 float(27294.5) float(54545) float(5450.1) 
32744.6 < 54545 float(32744.6) float(54545) float(5450.1) 
38194.7 < 54545 float(38194.7) float(54545) float(5450.1) 
43644.8 < 54545 float(43644.8) float(54545) float(5450.1) 
49094.9 < 54545 float(49094.9) float(54545) float(5450.1) 
54545 < 54545 float(54545) float(54545) float(5450.1) 
WHAT?

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-11-02 02:24 UTC] viliam dot kubis at gmail dot com
-Status: Open +Status: Closed
 [2010-11-02 02:24 UTC] viliam dot kubis at gmail dot com
I'm sorry, my mistake. Did not read carefully about floats in the manual. Sure you can't safely compare them for equality, but that also means you can't safely compare them with "<" and ">" operators. The code works when using BCMath. Thanks.
 [2010-11-02 02:33 UTC] pajoye@php.net
-Status: Closed +Status: Bogus
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 17:01:30 2024 UTC