Bug #81601 [NEW]: float - (int) float is sometimes bigger than 1
From: dktapps at pmmp dot io
Operating system: Linux
PHP version: 8.0.12
Package: Math related
Bug Type: Bug
Bug description:float - (int) float is sometimes bigger than 1
Description:
------------
I've seen this issue recur many times over the last few years, but never
figured out exactly what causes it.
This code:
https://github.com/pmmp/PocketMine-MP/blob/3dae87373154ad52ff6c27874f3fd93c9845a8af/src/pocketmine/entity/Human.php#L396
is intended to take a float and split it into its whole-number part (the
first argument) and its fractional part (the second argument).
However, sometimes I see crashes like these show in my telemetry:
Value 1.0323429203787 is outside the range 0 - 1
with a trace like this:
#1 pmsrc/src/pocketmine/entity/Human(396):
pocketmine\entity\Human->setXpAndProgress(integer 9, double
1.0323429203787)
#2 pmsrc/src/pocketmine/entity/Human(409):
pocketmine\entity\Human->setCurrentTotalXp(integer 158)
To the best of my understanding, this should be impossible.
For context, passing 158 into setCurrentTotalXp() causes $newLevel to
become float(9.922847983320086), which, when run through the offending
code on **my** machine, yields this result:
(int) $newLevel = int(9)
$newLevel - (int) $newLevel = float(0.9228479833200858)
which looks correct.
I have no idea what causes this problem and have never been able to
reproduce it firsthand, but such issues have appeared so frequently and
across several PHP versions that I believe this is a bug in PHP itself.
Expected result:
----------------
float - (int) float should never be larger than 1.
Actual result:
--------------
float - (int) float is sometimes slightly larger than 1.
--
Edit bug report at https://bugs.php.net/bug.php?id=81601&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=81601&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=81601&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=81601&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=81601&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=81601&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=81601&r=support
Expected behavior: https://bugs.php.net/fix.php?id=81601&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=81601&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=81601&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=81601&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=81601&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=81601&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=81601&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=81601&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=81601&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=81601&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=81601&r=mysqlcfg
Thread (10 messages)
- dktapps at pmmp dot io