Bug #75004 [Opn->Nab]: Certain floats * 100 type cast to int value one less then they should be
| From: | requinix@php.net | Date: | Fri, 28 Jul 2017 16:13:08 +0000 |
| Subject: | Bug #75004 [Opn->Nab]: Certain floats * 100 type cast to int value one less then they should be | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-210403@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=75004&edit=1
ID: 75004
Updated by: requinix@php.net
Reported by: c dot m dot tatro at gmail dot com
Summary: Certain floats * 100 type cast to int value one less
then they should be
-Status: Open
+Status: Not a bug
Type: Bug
Package: *General Issues
Operating System: ubuntu
PHP Version: 7.1.7
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.
Previous Comments:
------------------------------------------------------------------------
[2017-07-28 16:12:00] c dot m dot tatro at gmail dot com
Description:
------------
PHP 7.1.7-1+ubuntu14.04.1+deb.sury.org+1 (cli) (built: Jul 7 2017 10:07:42) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.1.7-1+ubuntu14.04.1+deb.sury.org+1, Copyright (c) 1999-2017, by Zend
Technologies
echo (int) (66.74*100); // 6673
echo (int) (35.55*100); // 3554
echo (int) (34.12*100); // 3411
To get a larger list run:
for ($i=0; $i<=1000; $i++) { echo (int) (((float)$i/100)*100) ."\r\n";}
Test script:
---------------
echo (int) (66.74*100);
echo (int) (35.55*100);
echo (int) (34.12*100);
for ($i=0; $i<=1000; $i++) { echo (int) (((float)$i/100)*100) ."\r\n";}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=75004&edit=1