#23626 closed defect (bug) (fixed)
wp_convert_bytes_to_hr tests and NaN
Reported by: | soulseekah | Owned by: | SergeyBiryukov |
---|---|---|---|
Milestone: | 3.6 | Priority: | normal |
Severity: | normal | Version: | |
Component: | General | Keywords: | has-patch |
Focuses: | Cc: |
Description
[1218/tests] were written for the deprecated wp_convert_bytes_to_hr
, these tests are broken at least on 64-bit machines, at most - on all machines.
On 64-bit PHP (PHP_INT_SIZE == 8) floating point does not match expected output (gets 1022.9990234375MB). The last digits in floating point should not be depended upon due to these inaccuracies. Rounding in PHP < 5.3 is not an option either, since rounding mode was introduced later and different systems get different results (round up vs. round down by default). So perhaps looking at error and discrepancy would be a decent solution (maybe even less error 0.00001?).
Next [23440], in the function itself we get (int)double(NAN
) result from feeding -1 and 0, which results in $power
to be a huge negative number instead of 0. This results in both a Warning (undefined array index) being thrown, and the "B" missing in tests, i.e. expected "NANB" != "NAN" and expected "0B" != "0".
Related #19067
Attachments (6)
Change History (19)
#3
@
12 years ago
See: http://www.php.net/manual/en/function.round.php#98704 for PHP < 5.3 round direction is not predictable it seems.
#4
@
12 years ago
In 1220/tests:
#5
@
12 years ago
- Owner set to SergeyBiryukov
- Resolution set to fixed
- Status changed from new to closed
In 23502:
#6
@
12 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
Still getting different results:
- 32-bit,
wp_convert_bytes_to_hr( -1 )
:NANB
- 64-bit,
wp_convert_bytes_to_hr( -1 )
:-1B
I didn't commit 19067.function.patch as is, because for 1 terabyte, the function would return "1B" (before [23502] it would be "1" and a notice).
Testing 23626.patch and 23626.test.patch now.
#8
@
12 years ago
Replying to soulseekah:
Perhaps it should return false for all sorts of weirdness? Or 0B.
It's supposed to return a string. It also does not state that $bytes
should be positive, so for "-1", I guess "-1B" is a more appropriate result than "0B".
We could also add "TB" to the array: 23626.2.patch, 23626.test.2.patch.
So far getting consistent results with the latest patches.
#9
@
12 years ago
In 1226/tests:
#11
@
11 years ago
In 1270/tests:
#12915 suggested rounding the output to 2 decimal digits.
#22295 also mentioned the notice.