|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2021-11-08 19:39 UTC] dktapps at pmmp dot io
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. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 06 00:00:02 2025 UTC |
Yes, the integer part of the float storage of the implicit integer cast is equivalent to the integer part of the float. But from the source you mentioned I see two numbers with different lengths and I suspect there is a problem with the scientific notation for 0. If you can also print with var_dump(sprintf('%00.53F', $float)); when in source it checks if > 0 so you will have two representations of the number that you can compare for debugging.