Re: [PHP-DEV] Proposal: change precision for output functions

2019-01-07 Thread Semen Dubina
> 08.01.2019, 00:39, "Legale.legale" :
> What proposal? I'm talking about elementary arithmetic.
>
> Take a look here:
> Https://jdoodle.com/embed/v0/Tgu

Yes, floating-point arithmetic says: '0.8!=0.1+0.7'.
jdoodle.com/a/Thv

Will we discuss this now?

-- Semen V. Dubina https://sam002.net/

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Inconsistent float to string vs. string to floatcasting

2019-01-07 Thread BohwaZ
AFAIK, gettext functions do depend on setlocale.

I wish so much that it wasn't the case (as you then need to have the
locale installed on the system), but it is, so setlocale definetely is
quite used in the wild and deprecating it seems a bit far-fetched
unless we can actually replace it with something else (better).

But gettext has other issues related to being cached in the current
process, as you need to restart apache if the compiled .mo files have
changed to get the new strings :(

Another function that is influenced by setlocale is strftime. This is
often the common way to display a date in a different language.

So I'm all for deprecating setlocale but before that we would need to
have something better for everything that's currently depending on it :)

BohwaZ

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Proposal: change precision for output functions

2019-01-07 Thread Legale.legale
What proposal? I'm talking about elementary arithmetic. 

Take a look here:
Https://jdoodle.com/embed/v0/Tgu
On Jan 7, 2019 10:32 PM, Semen Dubina  wrote:
>
>
> > 07.01.2019, 22:17, "Legale.legale" : 
> > I think your solution by changing precision is not good enough because 
> > float summation is still not working properly. 
> > 
> >  > var_dump(0.1 + 0.7); 
> > 
> > returns: 
> > 
> > 0.79 
> > 
> > expected: 0.8 
> > 
>
> Hi! 
>
> If you are about the proposal, then '0.1 + 0.7 !== 0.8'. 
> Why you expected 0.8? 
> Check, plz: https://3v4l.org/Ughn2 
>
>  -- Semen V. Dubina https://sam002.net/ 


Re: [PHP-DEV] Proposal: change precision for output functions

2019-01-07 Thread Semen Dubina


> 07.01.2019, 22:17, "Legale.legale" :
> I think your solution by changing precision is not good enough because float 
> summation is still not working properly.
>
>  var_dump(0.1 + 0.7);
>
> returns:
>
> 0.79
>
> expected: 0.8
>

Hi!

If you are about the proposal, then '0.1 + 0.7 !== 0.8'.
Why you expected 0.8?
Check, plz: https://3v4l.org/Ughn2

 -- Semen V. Dubina https://sam002.net/

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Proposal: change precision for output functions

2019-01-07 Thread Legale.legale
I think your solution by changing precision is not good enough because float 
summation is still not working properly.

 wrote:
>
> > 07.01.2019, 20:24, "Thomas Bley" : 
> > 
> > Hello, 
> > 
> > good point, having: 
> > 
> > echo ini_get('precision') . PHP_EOL; 
> > echo ini_get('serialize_precision') . PHP_EOL; 
> > echo json_encode(array('price' => round('45.99', 2))) . PHP_EOL; 
> > echo (0.1+0.7), json_encode(0.1+0.7) . PHP_EOL; 
> > 
> > gives (https://3v4l.org/ldgo8): 
> > 
> > Output for 7.1.0 - 7.3.0 
> > 14 
> > -1 
> > {"price":45.99} 
> > 0.80.7999 
> > 
> > Output for 5.3.6 - 5.6.38, 7.0.0 - 7.0.33 
> > 14 
> > 17 
> > {"price":45.99} 
> > 0.80.8 
> > 
> > what is the preferred way to upgrade from php 5.6 to 7.x in order to get 
> > the same results? 
> > 
> > Regards 
> > Thomas 
> > 
>
> Force 'serialize_precision': https://3v4l.org/coaWm 
> But remember - a float is not suitable for output. You need rounded and 
> formatted manually. 
>
> P.S. Try with JS: `JSON.stringify(0.1+0.7);` 
>
> -- Semen V. Dubina https://sam002.net/ 
>
> -- 
> PHP Internals - PHP Runtime Development Mailing List 
> To unsubscribe, visit: http://www.php.net/unsub.php 
>


Re: [PHP-DEV] Proposal: change precision for output functions

2019-01-07 Thread Semen Dubina
> 07.01.2019, 20:24, "Thomas Bley" :
>
> Hello,
>
> good point, having:
>
> echo ini_get('precision') . PHP_EOL;
> echo ini_get('serialize_precision') . PHP_EOL;
> echo json_encode(array('price' => round('45.99', 2))) . PHP_EOL;
> echo (0.1+0.7), json_encode(0.1+0.7) . PHP_EOL;
>
> gives (https://3v4l.org/ldgo8):
>
> Output for 7.1.0 - 7.3.0
> 14
> -1
> {"price":45.99}
> 0.80.7999
>
> Output for 5.3.6 - 5.6.38, 7.0.0 - 7.0.33
> 14
> 17
> {"price":45.99}
> 0.80.8
>
> what is the preferred way to upgrade from php 5.6 to 7.x in order to get the 
> same results?
>
> Regards
> Thomas
>

Force 'serialize_precision': https://3v4l.org/coaWm
But remember - a float is not suitable for output. You need rounded and 
formatted manually.

P.S. Try with JS: `JSON.stringify(0.1+0.7);`

-- Semen V. Dubina https://sam002.net/

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Proposal: change precision for output functions

2019-01-07 Thread Thomas Bley
Semen Dubina wrote on 07.01.2019 16:38:

> Hi, everyone!
> Original PR and description see: https://github.com/php/php-src/pull/3460.
> 
> Because of the accuracy constraint set by the 'precision' variable, debugging
> problems often occur, and many developers consider the limited accuracy to be 
> a
> feature of the language.
> For better compatibility with other languages and predictable behavior, I
> suggest changing the default value of the variable 'precision' to -1.
> In the tracker you can find several bugs in which people trusted output of
> 'var_dump' and 'echo':
> https://bugs.php.net/bug.php?id=66866
> https://bugs.php.net/bug.php?id=66959
> https://bugs.php.net/bug.php?id=68551
> https://bugs.php.net/bug.php?id=73358
> 
> Examples: https://3v4l.org/Mr4KM
> 
> If you know a case when it will violate some task, describe it, please. I 
> think
> that the trusting of FLOAT is a very bad practice.
> 
> -- Semen V. Dubina https://sam002.net/
> 
> -- 
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

Hello,

good point, having:

echo ini_get('precision') . PHP_EOL;
echo ini_get('serialize_precision') . PHP_EOL;
echo json_encode(array('price' => round('45.99', 2))) . PHP_EOL;
echo (0.1+0.7), json_encode(0.1+0.7) . PHP_EOL;

gives (https://3v4l.org/ldgo8):

Output for 7.1.0 - 7.3.0
14
-1
{"price":45.99}
0.80.7999

Output for 5.3.6 - 5.6.38, 7.0.0 - 7.0.33
14
17
{"price":45.99}
0.80.8

what is the preferred way to upgrade from php 5.6 to 7.x in order to get the 
same results?

Regards
Thomas


-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DEV] Proposal: change precision for output functions

2019-01-07 Thread Semen Dubina
Hi, everyone!
Original PR and description see: https://github.com/php/php-src/pull/3460.

Because of the accuracy constraint set by the 'precision' variable, debugging 
problems often occur, and many developers consider the limited accuracy to be a 
feature of the language.
For better compatibility with other languages and predictable behavior, I 
suggest changing the default value of the variable 'precision' to -1.
In the tracker you can find several bugs in which people trusted output of 
'var_dump' and 'echo':
https://bugs.php.net/bug.php?id=66866
https://bugs.php.net/bug.php?id=66959
https://bugs.php.net/bug.php?id=68551
https://bugs.php.net/bug.php?id=73358

Examples: https://3v4l.org/Mr4KM

If you know a case when it will violate some task, describe it, please. I think 
that the trusting of FLOAT is a very bad practice.

-- Semen V. Dubina https://sam002.net/

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php