1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
--TEST--
Decimal::shift
--SKIPIF--
<?php
if (!extension_loaded("decimal")) echo "skip";
?>
--FILE--
<?php
use Decimal\Decimal;
/**
* Shortcut to construct a new decimal.
*/
function decimal(...$args) { return new Decimal(...$args); }
$tests = [
/* A * B = C */
["1", -3, "0.001"],
["1", -2, "0.01"],
["1", -1, "0.1"],
["1", 0, "1"],
["1", 1, "1E+1"],
["1", 2, "1E+2"],
["1", 3, "1E+3"],
["1", -27, "1E-27"],
["1", 27, "1E+27"],
["0.5", -3, "0.0005"],
["0.5", -2, "0.005"],
["0.5", -1, "0.05"],
["0.5", 0, "0.5"],
["0.5", 1, "5"],
["0.5", 2, "5E+1"],
["0.5", 3, "5E+2"],
["1", -10000, "1E-10000"],
["1", 10000, "1E+10000"],
[ "NAN", 2, "NAN"],
[ "INF", 2, "INF"],
["-INF", 2, "-INF"],
];
foreach ($tests as $test) {
list($number, $exponent, $expect) = $test;
$result = decimal($number)->shift($exponent);
if ((string) $result !== $expect || $result->precision() !== 28) {
print_r(compact("number", "exponent", "result", "expect"));
}
}
?>
--EXPECT--
|