Bug #80163 [NEW]: An error in operating a cast to an int
| From: | peter dot j dot burling at skymesh dot com dot au | Date: | Wed, 30 Sep 2020 01:44:15 +0000 |
| Subject: | Bug #80163 [NEW]: An error in operating a cast to an int | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-229279@lists.php.net to get a copy of this message | ||
From: peter dot j dot burling at skymesh dot com dot au
Operating system: Linux - Fedora fc30.x86_64
PHP version: 7.3.22
Package: Math related
Bug Type: Bug
Bug description:An error in operating a cast to an int
Description:
------------
Casting to an int where a subtraction equals 0.2, when multiplied by 10
and cast to an int returns a value of 1. If the subtraction equals 0.3
then the result of the above cast will equal 3
Test script:
---------------
$kwatts = ((int)(($row[7]Ã - $row[4]) * 10))/10 ;
with $row[7] = 55.40
with $row[4] = 55.20
but returning a $kwatts value of 0.1
php > $a = 0.1;
php > $b = 0.3;
php > echo $b - $a ;
0.2
php > echo ($b - $a)* 10 ;
2
php > echo(int)($b - $a)* 10 ;
0
php > echo(int)(($b - $a)* 10) ;
1
php > echo(int)(10 * ($b - $a)) ;
1
php > echo(int)((10 * ($b - $a))) ;
1
--
Edit bug report at https://bugs.php.net/bug.php?id=80163&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=80163&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=80163&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=80163&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=80163&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=80163&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=80163&r=support
Expected behavior: https://bugs.php.net/fix.php?id=80163&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=80163&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=80163&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=80163&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=80163&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=80163&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=80163&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=80163&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=80163&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=80163&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=80163&r=mysqlcfg