Bug #71136 [Fbk->Opn]: periodic float numbers bug, works in php 5.6

From: Date: Wed, 16 Dec 2015 15:42:29 +0000
Subject: Bug #71136 [Fbk->Opn]: periodic float numbers bug, works in php 5.6
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-197932@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=71136&edit=1

 ID:                 71136
 User updated by:    djbrainnrg at gmail dot com
 Reported by:        djbrainnrg at gmail dot com
 Summary:            periodic float numbers bug, works in php 5.6
-Status:             Feedback
+Status:             Open
 Type:               Bug
 Package:            Unknown/Other Function
 Operating System:   Windows10 64bit / Apache 2.4.x
 PHP Version:        7.0.0
 Block user comment: N
 Private report:     N

 New Comment:

Yep, on Linux 64bit this is true.
On Windows 64bit not, here the PHP_INT_SIZE has changed.
For 5.6 this is 4, for PHP 7.0.0 this is 8

I guess, it's intended to have a higher INT_SIZE for PHP 7 because of 64bit.

But is the behaviour generally a bug that round() will not work with higher precision, like here
with 16 instead of 14? When you put in 14 it works like a charm.
https://3v4l.org/Wr7MD


Previous Comments:
------------------------------------------------------------------------
[2015-12-16 15:29:40] laruence@php.net

seems all php versions behavior same: https://3v4l.org/BrWp6

------------------------------------------------------------------------
[2015-12-16 14:56:56] djbrainnrg at gmail dot com

Description:
------------
Floating number precision in PHP 7 seems to be buggy or at least different to PHP 5.6.
A simple calculation with a periodic number see testscript.
This happens not with all periodic numbers.
In PHP 5.6.x this works fine and output "8.2" as expected.
In PHP 7.x this does NOT work and always output "8.199999999999", doesn't matter if
you use round() with precision or not.

Test script:
---------------
ini_set("precision", (PHP_INT_SIZE == 4) ? 14 : 16);
$nr = 8 + (1/10) + (9/90);
var_dump($nr, round($nr, 2));

Expected result:
----------------
"8.2" for the rounded result on all systems.

Actual result:
--------------
"8.1999999999999" also with round() called


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



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


Thread (6 messages)

« previous php.bugs (#197932) next »