Files
PhpSpreadsheet/tests/data/Calculation/Engineering/BITAND.php
T
oleibman 30c880b5e6 Bitwise Functions and 32-bit (#1900)
* 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.
2021-03-14 20:05:31 +01:00

34 lines
925 B
PHP

<?php
return [
[5, '21, 39'],
[64, '200, "84"'],
[8, '72.00, 184.00'],
['#VALUE!', '"ABC", "DEF"'],
['#VALUE!', '1, "DEF"'],
['#VALUE!', '"ABC", 1'],
['#NUM!', '12.00, 2.82E14'],
[5123456789, '5123456789, 5123456789'],
[4831908629, '5123456789, 7123456789'],
[21, '5123456789, 31'],
['#NUM!', '-5123456788, 1'],
['#NUM!', 'power(2, 50), 1'], // argument >= 2**48
['#NUM!', '1, power(2, 50)'], // argument >= 2**48
['#NUM!', '-2, 1'], // negative argument
['#NUM!', '2, -1'], // negative argument
['#NUM!', '-2, -1'], // negative argument
['#NUM!', '3.1, 1'], // non-integer argument
['#NUM!', '3, 1.1'], // non-integer argument
[0, '4, Q15'],
[0, '4, null'],
[0, '4, false'],
[1, '3, true'],
['exception', ''],
['exception', '2'],
[0, ', 4'],
[0, 'Q15, 4'],
[0, 'false, 4'],
[1, 'true, 5'],
[8, 'A2, 9'],
];