php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44092 exp() function returns incorrect result if passed hex
Submitted: 2008-02-10 17:20 UTC Modified: 2008-02-18 11:39 UTC
From: zoe@php.net Assigned:
Status: Closed Package: *Math Functions
PHP Version: 5.3CVS-2008-02-10 (CVS) OS: Linux 32
Private report: No CVE-ID: None
 [2008-02-10 17:20 UTC] zoe@php.net
Description:
------------
In PHP5.3 is a hex string is passed to exp() it is interpreted as 0 and 
the result of exp(0) = 1 is returned.

In PHP6 the hex string is correctly interpreted and the corrcet value is returned by exp().

I believe the PHP6 behaviour is preferred.

This patch http://www.pastebin.ca/898812 corrects the PHP5.3 behaviour.

Reproduce code:
---------------
--TEST--
Test exp() - pass exp hex string 
--INI--
precision=14
--FILE--
<?php
        $value= "0x5F";
        $res = exp($value);
        var_dump($res);
?>
--EXPECTF--
float(1.811239082889E+41)


Expected result:
----------------
See above

Actual result:
--------------
1

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-02-10 17:27 UTC] zoe@php.net
If this patch goes in, the test exp_error.phpt will need a small change too. I'm happy to do that.
 [2008-02-11 14:23 UTC] iliaa@php.net
Go ahead and apply the patch to the code & the test.
 [2008-02-11 16:07 UTC] felipe@php.net
Hello Ilia, 
in this case, should all math functions in ext/standard/ use the new parsing parameter, no? Only fix the exp() sounds wrong to me...
 [2008-02-11 16:22 UTC] zoe@php.net
Felipe - I think they should probably all change. I'm happy to work through one at a time (or maybe you'd like to fix some?), I don't really want to do them all in one update. I used exp() to make sure that I was doing the right thing. Quite a few of the tests would also need changing (because I worked around this for a while). I think sin() and cos() at least are wrong. I've also got bugs pending in number_format() and hypot() - which *might* be the same issue.

Zoe
 [2008-02-12 07:36 UTC] zoe@php.net
commited fix to /ext/standard/math.c and /ext/standard/tests/math/exp_error.phpt in PHP5.3 and PHP 5.2 
 [2008-02-13 15:40 UTC] bjori@php.net
(fix summary)
 [2008-02-18 11:39 UTC] felipe@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Nov 11 16:01:30 2024 UTC