Bug #72820 [NEW]: simple float to int conversation bug (input param: 0.2 or -0.2)
From: denton85 at gmail dot com
Operating system: Ubuntu 16.04, Win10, Win7
PHP version: Irrelevant
Package: Math related
Bug Type: Bug
Bug description:simple float to int conversation bug (input param: 0.2 or -0.2)
Description:
------------
The magic number is: 0.2 or -0.2
number - number = 0.2 or -0.2
then int conversion return bad result.
I tried with (int) or intval. Same result.
We tried with Win7, Win10 and Ubuntu 16.04
ubuntu's php version (official, installed with ap-get):
PHP 7.0.8-0ubuntu0.16.04.2 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.8-0ubuntu0.16.04.2, Copyright (c) 1999-2016,
by Zend Technologies
Test script:
---------------
<?php
echo "<pre>";
$var = (1-1.2)*100;
var_dump($var); //float(-20)
$var2 = (-0.2)*100;
var_dump($var2); //float(-20)
$var_int = (int)$var;
var_dump($var_int); //int(-19) ** INCORRECT RESULT **
$var2_int = (int)$var2;
var_dump($var2_int); //int(-20)
echo "</pre>";
//I changed values and no problem
echo "<pre>";
$var = (2-1.2)*100;
var_dump($var); //float(80)
$var2 = (0.8)*100;
var_dump($var2); //float(80)
$var_int = (int)$var;
var_dump($var_int); //int(80)
$var2_int = (int)$var2;
var_dump($var2_int); //int(80)
echo "</pre>";
--
Edit bug report at https://bugs.php.net/bug.php?id=72820&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=72820&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=72820&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=72820&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=72820&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=72820&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=72820&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=72820&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=72820&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=72820&r=support
Expected behavior: https://bugs.php.net/fix.php?id=72820&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=72820&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=72820&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=72820&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=72820&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=72820&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=72820&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=72820&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=72820&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=72820&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=72820&r=mysqlcfg
Thread (2 messages)
- denton85 at gmail dot com