Bug #81601 [Com]: float - (int) float is sometimes bigger than 1
Edit report at https://bugs.php.net/bug.php?id=81601&edit=1
ID: 81601
Comment by: dktapps at pmmp dot io
Reported by: dktapps at pmmp dot io
Summary: float - (int) float is sometimes bigger than 1
Status: Open
Type: Bug
Package: Math related
Operating System: Linux
PHP Version: 8.0.13
Block user comment: N
Private report: N
New Comment:
I'll also mention that NO references are used in the stack, so I don't know how this is
happening.
Previous Comments:
------------------------------------------------------------------------
[2021-12-03 12:58:47] dktapps at pmmp dot io
Hi all, this issue recently occurred again despite additional checks in the code specifically
designed to trap this edge case. It looks like the value must be getting corrupted somewhere.
Unsuccessful trap: https://github.com/pmmp/PocketMine-MP/blob/6b7d0307afb36a7faca2dd65734e15000baf17ba/src/pocketmine/entity/Human.php#L401
Error thrown here: https://github.com/pmmp/PocketMine-MP/blob/6b7d0307afb36a7faca2dd65734e15000baf17ba/src/pocketmine/entity/Attribute.php#L196
https://crash.pmmp.io/view/5558770
------------------------------------------------------------------------
[2021-11-10 13:28:24] antonino dot spampinato86 at gmail dot com
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.
------------------------------------------------------------------------
[2021-11-10 09:39:26] php at leinertco dot com
Try to pass $newLevel as 3rd argument in setXpAndProgress, so you have its value in your logs. Maybe
this will help :/
------------------------------------------------------------------------
[2021-11-09 12:14:31] dktapps at pmmp dot io
I do know of several ways to work around it (fmod(f, 1) being the first thing I thought of), but I
thought this should be investigated anyway.
------------------------------------------------------------------------
[2021-11-09 09:58:53] nikic@php.net
If float is larger than INT_MAX, then float - (int) float can trivially be larger than 1. However,
you seem to be working with numbers that are much smaller than that.
I do wonder why this is not implemented as $float - floor($float) though, that seems like the more
natural way to express it, and should avoid edge cases.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=81601
--
Edit this bug report at https://bugs.php.net/bug.php?id=81601&edit=1
Thread (10 messages)