php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69188 The constant INF is set to float(0)
Submitted: 2015-03-04 21:14 UTC Modified: 2021-01-24 04:22 UTC
Votes:6
Avg. Score:4.7 ± 0.7
Reproduced:6 of 6 (100.0%)
Same Version:4 (66.7%)
Same OS:4 (66.7%)
From: manuel at moosnet dot de Assigned: cmb (profile)
Status: No Feedback Package: Math related
PHP Version: Irrelevant OS: SunOS 5.10
Private report: No CVE-ID: None
 [2015-03-04 21:14 UTC] manuel at moosnet dot de
Description:
------------
First, sorry, this is on a shared hoster (strato.de) environment and I do not have full control over the PHP version that is used; I cannot use anything current, only a variety of older versions.

Essentially, the bug is that INF is exactly equal to 0 on SunOS 5.10. NAN seems to work fine. No string conversion is involved as far as I can tell.

The CPU seems to be a generic x86 and Python treats INF and NAN correctly, so it seems the FPU is not the culprit.

The only mention of this behavior I found elsewhere is this old stackoverflow question:
http://stackoverflow.com/questions/11667512/php-inf-has-value-zero

Here's the output of a couple of test runs of the test script:
>>> uname -a
SunOS aklathep 5.10 Generic_142901-13 i86pc i386 i86pc
>>> php52 inftest.php
X-Powered-By: PHP/5.2.17
Content-type: text/html

float(0)
float(NAN)
>>> php53 inftest.php
X-Powered-By: PHP/5.3.29
Content-type: text/html

float(0)
float(NAN)
>>> php55 inftest.php
X-Powered-By: PHP/5.5.18
Content-type: text/html

float(0)
float(NAN)
>>> php56 inftest.php
X-Powered-By: PHP/5.6.2
Content-type: text/html; charset=iso-8859-1

float(0)
float(NAN)

Full version information:
>>> php52 --version
PHP 5.2.17 (cgi-fcgi) (built: Jul 30 2014 15:57:46)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies
>>> php53 --version
PHP 5.3.29 (cgi-fcgi) (built: Aug 20 2014 15:52:05)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2014 Zend Technologies
>>> php55 --version
PHP 5.5.18 (cgi-fcgi) (built: Oct 17 2014 12:36:29)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
>>> php56 --version
PHP 5.6.2 (cgi-fcgi) (built: Oct 16 2014 13:30:19)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2014 Zend Technologies


Test script:
---------------
<?php
$v = INF;
var_dump($v);
$v = NAN;
var_dump($v);


Expected result:
----------------
float(INF)
float(NAN)


Actual result:
--------------
float(0)
float(NAN)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-08-25 12:54 UTC] fisharebest at gmail dot com
One of users (also a strato.de customer) has reported the same issue, across a range of PHP versions.

I have just built a SunOS 11.2 server and compiled PHP from source.

It works as expected.

This suggests the problem is specific to servers at strato.de.
 [2015-08-26 13:07 UTC] wagner at strato-rz dot de
Hi, 

I am a developer at strato.
It seems that the problem is
with SUN Solaris 5.10.

I found that the code in ext/standard/basic_functions.c: php_get_inf()
uses atof to determine the value of "INF".

To test the matter I wrote a test what "INF" would be
if php uses a different way to determine the value

------------------------------------------------
CODE:
------------------------------------------------
int main(void) 
{
	#define PHP_DOUBLE_INFINITY_HIGH       0x7ff00000

	double val = 0.0;
	((uint32_t*)&val)[1] = PHP_DOUBLE_INFINITY_HIGH;
	((uint32_t*)&val)[0] = 0;
	printf("__i386__: %f\n",val);

	double atf = atof("INF");
	printf("atof: %f\n",atf);

	printf("fract: %f\n",1.0/0.0);
	
	return 0;
}
------------------------------------------------
OUTPUT:
------------------------------------------------
__i386__: Inf
atof: 0.000000
fract: Inf
------------------------------------------------

This shows that using atof() for "INF" does not work
as expected and it is not server specific but a problem
in the Solaris OS (5.10) itself.

Never the less, the other methods php could use would result
in a correct value.

Defining HAVE_ATOF_ACCEPTS_INF on Solaris 5.10 seems wrong
at first, although its a strange behaviour by the OS.

Maybe there is something wrong with autotools we are using,
that are an older version.

I will investigate some more and write down my results here
 [2016-07-07 13:19 UTC] wagner at strato-rz dot de
Just tested it with Solaris 11,
we are seeing the same problem there.

What about my proposed fix ?
(Not defining HAVE_ATOF_ACCEPTS_INF on Solaris machines)

[solaris11 ~]# ./inftest 
__i386__: Inf
atof: 0.000000
fract: Inf
[solaris11 ~]# uname -a
SunOS solaris11 5.11 11.3 i86pc i386 i86pc

Just for clarification, it's not a build breaker,
the is_finite() PHP-function seems to be buggy on 
Solaris.
 [2016-08-10 15:09 UTC] tycholursen at gmail dot com
@wagner at strato-rz dot de
Are you aware of the fact that this long standing bug on the Strato servers prevents MediaWiki version 1.27.0 from functioning?
Please have a look at https://phabricator.wikimedia.org/T139559 for clarification.
It contains a backtrace of the "ParameterAssertionException: Bad value for parameter maxKeys: must be above zero" I encountered in an attempt to install MediaWiki 1.27.0 on Strato servers.
Please fix it!
 [2016-09-07 16:59 UTC] chris at chrisjean dot com
@manuel at moosnet dot de

You suggested that the tooling used to provision the servers could be the source of the issue. I suggest that you dig deeper into that as I ran your sample C code on a fresh install of Solaris 11.3 and did not see a problem. This points to a problem in your provisioning process, not a compatibility problem with Solaris.

$ uname -a
SunOS solaris 5.11 11.3 i86pc i386 i86pc
$ ./atof
__i386__ Inf
atof: Inf
fract: Inf
 [2016-12-15 11:35 UTC] wagner at strato-rz dot de
We currently have patched our PHP 7 version to determine the value of "INF" correctly.

The problem is that "configure" does not work with Solaris 10 correctly and defines HAVE_ATOF_ACCEPTS_INF without checking the value of atof(INF).

I have to put in some more work to provide a proper patch for this to php.net. If you are experiencing this error please switch to PHP 7.
 [2016-12-20 04:43 UTC] tycholursen at gmail dot com
Hi, I just tested with a fresh install of MediaWiki 1.27.1 and php version 7 on Strato servers.
Seems to work OK for me now.
 [2021-01-13 16:12 UTC] cmb@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2021-01-13 16:12 UTC] cmb@php.net
If this is still unresolved for any of the actively supported PHP
versions[1], could someone with access to such an environment
please provide a suitable PR for the respective detection code[2]?

[1] <https://www.php.net/supported-versions.php>
[2] <https://github.com/php/php-src/blob/php-7.4.14/Zend/Zend.m4#L423-L447>
 [2021-01-24 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 [2021-01-24 16:46 UTC] manuel at moosnet dot de
All seems to be fine, I reran the test script in the strato shared environment. In the meantime, the only PHP versions available are 8.0.0 and 7.2.34, and both correctly print float(INF).
Thanks!
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 14:01:32 2024 UTC