When setting a value for an index using a formula to calculate the index, something like
$arr[((40.9+0.00004)*100000)] = 1;
,
in the expected result my array should have the value for index as so: [4090004]=>1
;
instead I got [4090003]=>1
.
Can someone please give me an insight into what's going on?
I was able to get around this by casting the index to a string $arr[(string) ((40.9+0.0004)*100000)] = 1;
, but I would like to understand the underlying mechanics that caused this to happen.
UPDATE
This is not directly connected to this question Is floating point math broken? — while the answer might have to do with that floating point bug, I am trying to understand how it effects me here.