Bug #68065 [NEW]: In some cases intval after floatval gives unexpected results
| From: | kstirn at gmail dot com | Date: | Sat, 20 Sep 2014 19:10:21 +0000 |
| Subject: | Bug #68065 [NEW]: In some cases intval after floatval gives unexpected results | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-187627@lists.php.net to get a copy of this message | ||
From: kstirn at gmail dot com
Operating system: Windows
PHP version: Irrelevant
Package: Math related
Bug Type: Bug
Bug description:In some cases intval after floatval gives unexpected results
Description:
------------
See test script - after multiplication and floatval, intval gives
unexpected (wrong) result.
This only seems to happen with some special initial $a floats, not in
all cases.
I know floating point precision cannot be trusted, but in this case it
may be hard to blame it?
Tested on Windows 7 and Linux (CentOS 6) with PHP 5.3.29 and 5.6.0
Test script:
---------------
$a = 1.2812;
$a = $a * 10000;
echo "$a<br>";
$a = floatval($a);
echo "$a<br>";
$a = intval($a);
echo "$a<br>";
Expected result:
----------------
12812
12812
12812
Actual result:
--------------
12812
12812
12811
--
Edit bug report at https://bugs.php.net/bug.php?id=68065&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=68065&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=68065&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=68065&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=68065&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=68065&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=68065&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=68065&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=68065&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=68065&r=support
Expected behavior: https://bugs.php.net/fix.php?id=68065&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=68065&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=68065&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=68065&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=68065&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=68065&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=68065&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=68065&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=68065&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=68065&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=68065&r=mysqlcfg