php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80286 Changing precision ini setting has no effect on const expressions
Submitted: 2020-10-27 08:00 UTC Modified: 2020-10-27 08:55 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: is dot malozemov at ya dot ru Assigned:
Status: Verified Package: *Math Functions
PHP Version: >=7 OS: Any
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2020-10-27 08:00 UTC] is dot malozemov at ya dot ru
Description:
------------
Math operations ignores precision option in php.ini (php 7+);
Precision is works for PHP 5.

Test script:
---------------
<?php

$precision = 18;

while($precision--) {
 ini_set('precision', $precision);
 echo $precision.":".(342349.23 - 341765.07)."\n";
}


Expected result:
----------------
17:584.15999999997439
16:584.1599999999744
15:584.159999999974
14:584.15999999997
13:584.16
12:584.16
11:584.16
10:584.16
9:584.16
8:584.16
7:584.16
6:584.16
5:584.16
4:584.2
3:584
2:5.8E+2
1:6.0E+2
0:6.0E+2

Actual result:
--------------
17:5.8E+2
16:5.8E+2
15:5.8E+2
14:5.8E+2
13:5.8E+2
12:5.8E+2
11:5.8E+2
10:5.8E+2
9:5.8E+2
8:5.8E+2
7:5.8E+2
6:5.8E+2
5:5.8E+2
4:5.8E+2
3:5.8E+2
2:5.8E+2
1:5.8E+2
0:5.8E+2


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-10-27 08:55 UTC] daverandom@php.net
-Summary: Math operation with precision in php.ini +Summary: Changing precision ini setting has no effect on const expressions -Status: Open +Status: Verified -Operating System: Linux Ubuntu 20.04 LTS +Operating System: Any -PHP Version: 7.3.23 +PHP Version: >=7
 [2020-10-27 08:55 UTC] daverandom@php.net
This issue occurs when a constant floating point operation is performed mid-string, the result is computed and cast to string at compile time, so changing the ini option has no effect at run time.

https://3v4l.org/jjJZP
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Sat Dec 05 06:01:23 2020 UTC