Bug #80286 [Com]: Changing precision ini setting has no effect on const expressions

From: Date: Wed, 05 Jul 2023 12:13:48 +0000
Subject: Bug #80286 [Com]: Changing precision ini setting has no effect on const expressions
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-244884@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80286&edit=1

 ID:                 80286
 Comment by:         vishalhoods at gmail dot com
 Reported by:        is dot malozemov at ya dot ru
 Summary:            Changing precision ini setting has no effect on
                     const expressions
 Status:             Verified
 Type:               Bug
 Package:            *Math Functions
 Operating System:   Any
 PHP Version:        >=7
 Block user comment: N
 Private report:     N

 New Comment:

Daily Job Update is Online Platform are Available. More info: (https://dailyjobupdate.com)github.com


Previous Comments:
------------------------------------------------------------------------
[2020-10-27 08:55:36] 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

------------------------------------------------------------------------
[2020-10-27 08:00:39] 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



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=80286&edit=1


Thread (3 messages)

« previous php.bugs (#244884) next »