mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-08-24 22:58:09 +00:00
30c880b5e6
* Bitwise Functions and 32-bit When running the test suite with 32-bit PHP, a failure was reported in BITLSHIFT. In fact, all of the following are vulnerable to problems, and didn't report any failures only because of a scarcity of tests: - BITAND - BITOR - BITXOR - BITRSHIFT - BITLSHIFT Those last 2 can be resolved fairly easily by using multiplication by a power of 2 rather than shifting. The first 3 are a tougher nut to crack, and I will continue to think how they might best be approached. For now, I have added skippable tests for each of them, which at least documents the problem. Aside from adding many new tests, some bugs were correctd: - The function list in Calculation.php pointed BITXOR to BITOR. - All 5 functions allow null/false/true parameters. - BIT*SHIFT shift amount must be numeric, can be negative, allows decimal portion (which is truncated to integer), and has an absolute value limit of 53. - Because BITRSHIFT allows negative shift amount, its result can overflow (in which case return NAN). - All 5 functions disallow negative parameters (except ...SHIFT second parameter). This was coded, but the code had been thwarted by an earlier is_int test. * Full Support for AND/OR/XOR on 32-bit Previous version did not support operands 2**32 through 2**48.
36 lines
1001 B
PHP
36 lines
1001 B
PHP
<?php
|
|
|
|
return [
|
|
[5, '20, 2'],
|
|
[3, '52, "4"'],
|
|
['#VALUE!', '"ABC", 5'],
|
|
['#VALUE!', '5, "ABC"'],
|
|
['#NUM!', '1, -48'], // result too large
|
|
['#NUM!', '1.1, 2'], // first arg must be integer
|
|
[1, '4, 2.1'], // second arg will be truncated
|
|
['#NUM!', '0, 54'], // second arg too large
|
|
[0, '0, 5'],
|
|
['#NUM!', '-16, 2'], // first arg can't be negative
|
|
[4, '1, -2'], // negative shift permitted
|
|
[4, '1, -2.1'], // negative shift and (ignored) fraction permitted
|
|
[4, '4, Q15'],
|
|
[4, '4, null'],
|
|
[4, '4, false'],
|
|
[2, '4, true'],
|
|
['exception', ''],
|
|
['exception', '2'],
|
|
[0, ', 4'],
|
|
[0, 'Q15, 4'],
|
|
[4, '4, q15'],
|
|
[4, '4, false'],
|
|
[2, '4, true'],
|
|
[0, 'false, 4'],
|
|
[0, 'true, 4'],
|
|
[16, 'true, -4'],
|
|
[4, 'A2, 1'],
|
|
[8000000000, '1000000000, -3'], // result > 2**32
|
|
[8000000000, '16000000000, 1'], // argument > 2**32
|
|
['#NUM!', 'power(2,50), 1'], // argument >= 2**48
|
|
['1', 'power(2, 47), 47'],
|
|
];
|