php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31504 -Infinity value returned for long float nums
Submitted: 2005-01-12 03:39 UTC Modified: 2005-01-14 04:13 UTC
From: charlesb at ekit-inc dot com Assigned: derick (profile)
Status: Closed Package: Variables related
PHP Version: 4.3.10 OS: sol9 i86, sol8 sparc, sol9 sparc
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: charlesb at ekit-inc dot com
New email:
PHP Version: OS:

 

 [2005-01-12 03:39 UTC] charlesb at ekit-inc dot com
Description:
------------
Basically we're seeing long floats being given a string value of -Infinity, even if we explicitly cast the variable.  Python can handle these vars no problem, don't see why PHP can't?  

Thanks


Reproduce code:
---------------
<?php
 
$a = '6.48261999999999982691178956883959472179';
 
$c = (double) $a;
 
$b = sprintf("%0.2f", $c);
 
print $c.' '.$b;
 
?>


Expected result:
----------------
6.48261999999999982691178956883959472179 6.48


Actual result:
--------------
-Infinity -0N

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-01-12 09:13 UTC] derick@php.net
This works fine for me on Linux, I will need access to a solaris machine with GDB installed to try to fix this... it's most likely related to our new zend_strtod functions.
 [2005-01-13 03:41 UTC] charlesb at ekit-inc dot com
Can't help you with access to a sol box, but I can confirm it is that function at fault.  On FC 1 the following C code produces the correct result but on solaris it produces 
-Inf, ie is a bug.

You might be interested to know that the solaris strtod function can handle the number no problems, so if you rolled your own zend_strtod function to get around an OS bug, you don't need to for Solaris :)

char *cp;
double a = zend_strtod("6.48261999999999982691178956883959472179", &cp);
printf("%g\n", a);
 [2005-01-13 03:53 UTC] charlesb at ekit-inc dot com
I'll just add that I've only confirmed that c-code problem on sol9/x86.
 [2005-01-13 04:11 UTC] charlesb at ekit-inc dot com
OK, this looks like the error discussed in bugs 31107 and 31121 (but is reported as a build error instead, which is why I missed it).

It's to do with php's test being endian is wrong for solaris and we presume will see the fix in 4.3.11.  (or we'll grab the snapshot).

Case closed (for now).
 [2005-01-13 08:17 UTC] derick@php.net
Can you please try the snapshot? We can't test this as we don't have access to a sol. box and it would be a shame if it still borks on solaris in 4.3.11.

And FYI, it's not because we work around an OS bug, it is because we need a non-locale aware version.
 [2005-01-14 04:11 UTC] charlesb at ekit-inc dot com
OK, I built the stable snapshot on sol9/x86 and that huge number comes up as  6.48262, rather than -Inf.  

So yeah, it works. :)  Cheers
 [2005-01-14 04:13 UTC] sniper@php.net
Works -> closed.

 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Mon Sep 16 02:01:26 2019 UTC