php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #54017 allocation error of float variable
Submitted: 2011-02-14 17:48 UTC Modified: 2011-02-14 17:54 UTC
From: davidmdvd at gmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.3.5 OS: Windows 7 64(bits)
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: davidmdvd at gmail dot com
New email:
PHP Version: OS:

 

 [2011-02-14 17:48 UTC] davidmdvd at gmail dot com
Description:
------------
<?php
	$ar = array();
	
	$ar[] = 0.85;
	$ar[] = 0.85;
	$ar[] = 0.85;
	$ar[] = 0.85;
	$ar[] = 0.85;
	$ar[] = 0.85;
	$ar[] = 0.85;
	$ar[] = 0.85;
	$ar[] = 0.85;
	$ar[] = 0.85;
	$ar[] = 0.85;
	$ar[] = 0.85;
	$ar[] = 0.85;
	$ar[] = 0.85;
	$ar[] = 0.85;
	$ar[] = 0.85;
	$ar[] = 0.85;
	$ar[] = 0.85;
	$ar[] = 0.85;
	$ar[] = 0.425;
	$ar[] = 0.425;
	$ar[] = 0.425;
	
	if ( array_sum($ar)>=17 )
		"It was to come."
?>

Test script:
---------------
<?php
	$ar = array();
	
	$ar[] = 0.85;
	$ar[] = 0.85;
	$ar[] = 0.85;
	$ar[] = 0.85;
	$ar[] = 0.85;
	$ar[] = 0.85;
	$ar[] = 0.85;
	$ar[] = 0.85;
	$ar[] = 0.85;
	$ar[] = 0.85;
	$ar[] = 0.85;
	$ar[] = 0.85;
	$ar[] = 0.85;
	$ar[] = 0.85;
	$ar[] = 0.85;
	$ar[] = 0.85;
	$ar[] = 0.85;
	$ar[] = 0.85;
	$ar[] = 0.85;
	$ar[] = 0.425;
	$ar[] = 0.425;
	$ar[] = 0.425;
	
	if ( array_sum($ar)>=17 )
		"It was to come."
?>

Expected result:
----------------
It was to come.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-02-14 17:54 UTC] pajoye@php.net
-Status: Open +Status: Bogus
 [2011-02-14 17:54 UTC] pajoye@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://www.floating-point-gui.de/

Thank you for your interest in PHP.


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Jul 14 18:01:33 2025 UTC