Bug #71136 [NEW]: periodic float numbers bug, works in php 5.6

From: Date: Wed, 16 Dec 2015 14:56:57 +0000
Subject: Bug #71136 [NEW]: periodic float numbers bug, works in php 5.6
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-197926@lists.php.net to get a copy of this message
From:             djbrainnrg at gmail dot com
Operating system: Windows10 64bit / Apache 2.4.x
PHP version:      7.0.0
Package:          Unknown/Other Function
Bug Type:         Bug
Bug description:periodic float numbers bug, works in php 5.6

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 bug report at https://bugs.php.net/bug.php?id=71136&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=71136&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=71136&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=71136&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=71136&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=71136&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=71136&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=71136&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=71136&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=71136&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=71136&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=71136&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=71136&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=71136&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=71136&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=71136&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=71136&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=71136&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=71136&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=71136&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=71136&r=mysqlcfg



Thread (6 messages)

« previous php.bugs (#197926) next »