php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #36493 Unable to determine maximum floating point b
Submitted: 2006-02-23 07:11 UTC Modified: 2006-10-09 12:30 UTC
From: terrafrost at gmail dot com Assigned: tony2001 (profile)
Status: Wont fix Package: Math related
PHP Version: 5.1.2, 4.4.2 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
42 - 8 = ?
Subscribe to this entry?

 
 [2006-02-23 07:11 UTC] terrafrost at gmail dot com
Description:
------------
I've ran into some difficulty attempting to figure out what the maximum size of the exponent in floats is.

Reproduce code:
---------------
<?
$x = 2;
$y = 1;
for ($bits=1; ($x*=2) > ($y*=2); $bits++);
echo $bits;
?> 

Expected result:
----------------
Assuming php.net's statement about the 64-bit IEEE standard being the most common representation of float, I'd expect to get 1024 as the result.

Actual result:
--------------
On Windows, I do indeed get the correct result.  On Linux, all I get are timeout errors.  I've tried it with both PHP4 and PHP5 and get the same results for each.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-10-09 12:30 UTC] tony2001@php.net
The solution is actually quite simple - you should check if the numbers are still finite, because one infinity is not equal to another infinity and comparing them with < or > is pointless. 
See the code below:
<?php
$x = 2;
$y = 1;
for ($bits=1; ($x*=2) > ($y*=2) && is_finite($x) && is_finite($y); $bits++);
echo $bits;
?>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 03:01:32 2024 UTC