Bug #81285 [Opn->Nab]: Division of floats results strange values
| From: | cmb@php.net | Date: | Fri, 23 Jul 2021 13:55:45 +0000 |
| Subject: | Bug #81285 [Opn->Nab]: Division of floats results strange values | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-235311@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=81285&edit=1
ID: 81285
Updated by: cmb@php.net
Reported by: rico dot humme at gmail dot com
Summary: Division of floats results strange values
-Status: Open
+Status: Not a bug
Type: Bug
Package: Math related
Operating System: Ubuntu
PHP Version: 8.0.8
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
Floating point values have a limited precision. Hence a value might
not have the same string representation after any processing. That also
includes writing a floating point value in your script and directly
printing it without any mathematical operations.
If you would like to know more about "floats" and what IEEE
754 is, read this:
http://www.floating-point-gui.de/
Thank you for your interest in PHP.
var_dump() uses serialize_precision instead of precision as of PHP
8.0.0, see <https://3v4l.org/s82d8>.
Previous Comments:
------------------------------------------------------------------------
[2021-07-23 13:51:19] rico dot humme at gmail dot com
Description:
------------
I've come across this as trying to find a workaround for fmod()
Calculations:
9.6 / 3.2
9.9 / 3.3
Results:
Before PHP 8:
float(3)
float(3)
PHP 8+:
float(2.9999999999999996)
float(3.0000000000000004)
Test script:
---------------
Test script for testing on multiple versions:
https://3v4l.org/9bRl5
Expected result:
----------------
Result should return float(3) on all versions
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=81285&edit=1