parent
16787142d6
commit
7ae7e12ad8
14 changed files with 891 additions and 0 deletions
@ -0,0 +1,28 @@ |
|||||||
|
--TEST-- |
||||||
|
Test hrtime() aligns with microtime() |
||||||
|
--FLAKY-- |
||||||
|
This test frequently fails in CI |
||||||
|
--FILE-- |
||||||
|
<?php |
||||||
|
|
||||||
|
$m0 = microtime(true); |
||||||
|
$h0 = hrtime(true); |
||||||
|
for ($i = 0; $i < 1024*1024; $i++); |
||||||
|
$h1 = hrtime(true); |
||||||
|
$m1 = microtime(true); |
||||||
|
|
||||||
|
$d0 = ($m1 - $m0)*1000000000.0; |
||||||
|
$d1 = $h1 - $h0; |
||||||
|
|
||||||
|
/* Relative uncertainty. */ |
||||||
|
$d = abs($d0 - $d1)/$d1; |
||||||
|
|
||||||
|
if ($d > 0.05) { |
||||||
|
print "FAIL, $d"; |
||||||
|
} else { |
||||||
|
print "OK, $d"; |
||||||
|
} |
||||||
|
|
||||||
|
?> |
||||||
|
--EXPECTF-- |
||||||
|
OK, %f |
||||||
@ -0,0 +1,15 @@ |
|||||||
|
--TEST-- |
||||||
|
Test hrtime() return array |
||||||
|
--FILE-- |
||||||
|
<?php |
||||||
|
|
||||||
|
var_dump(hrtime()); |
||||||
|
|
||||||
|
?> |
||||||
|
--EXPECTF-- |
||||||
|
array(2) { |
||||||
|
[0]=> |
||||||
|
int(%d) |
||||||
|
[1]=> |
||||||
|
int(%d) |
||||||
|
} |
||||||
@ -0,0 +1,31 @@ |
|||||||
|
--TEST-- |
||||||
|
intdiv functionality |
||||||
|
--FILE-- |
||||||
|
<?php |
||||||
|
var_dump(intdiv(3, 2)); |
||||||
|
var_dump(intdiv(-3, 2)); |
||||||
|
var_dump(intdiv(3, -2)); |
||||||
|
var_dump(intdiv(-3, -2)); |
||||||
|
var_dump(intdiv(PHP_INT_MAX, PHP_INT_MAX)); |
||||||
|
var_dump(intdiv(PHP_INT_MIN, PHP_INT_MIN)); |
||||||
|
try { |
||||||
|
var_dump(intdiv(PHP_INT_MIN, -1)); |
||||||
|
} catch (Throwable $e) { |
||||||
|
echo "Exception: " . $e->getMessage() . "\n"; |
||||||
|
} |
||||||
|
try { |
||||||
|
var_dump(intdiv(1, 0)); |
||||||
|
} catch (Throwable $e) { |
||||||
|
echo "Exception: " . $e->getMessage() . "\n"; |
||||||
|
} |
||||||
|
|
||||||
|
?> |
||||||
|
--EXPECT-- |
||||||
|
int(1) |
||||||
|
int(-1) |
||||||
|
int(-1) |
||||||
|
int(1) |
||||||
|
int(1) |
||||||
|
int(1) |
||||||
|
Exception: Division of PHP_INT_MIN by -1 is not an integer |
||||||
|
Exception: Division by zero |
||||||
@ -0,0 +1,42 @@ |
|||||||
|
--TEST-- |
||||||
|
log() tests |
||||||
|
--FILE-- |
||||||
|
<?php |
||||||
|
echo "On failure, please mail result to php-dev@lists.php.net\n"; |
||||||
|
for ($x = 0, $count= 0; $x < 200; $x++) { |
||||||
|
$x2 = (int) exp(log($x)); |
||||||
|
// e ^ log(x) should be close in range to x |
||||||
|
if (($x2 < ($x + 2)) && ($x2 > ($x - 2))) { |
||||||
|
$count++; |
||||||
|
} else { |
||||||
|
print "$x : $x2\n"; |
||||||
|
} |
||||||
|
} |
||||||
|
print $count . "\n"; |
||||||
|
|
||||||
|
// Now test the base form of log |
||||||
|
for ($base = 2; $base < 11; $base++) { |
||||||
|
for ($x = 0, $count= 0; $x < 50; $x++) { |
||||||
|
$x2 = (int) pow($base, log($x, $base)); |
||||||
|
// base ^ log(x) should be close in range to x |
||||||
|
if (($x2 < ($x + 2)) && ($x2 > ($x - 2))) { |
||||||
|
$count++; |
||||||
|
} else { |
||||||
|
print "base $base: $x : $x2\n"; |
||||||
|
} |
||||||
|
} |
||||||
|
print $count . "\n"; |
||||||
|
} |
||||||
|
?> |
||||||
|
--EXPECT-- |
||||||
|
On failure, please mail result to php-dev@lists.php.net |
||||||
|
200 |
||||||
|
50 |
||||||
|
50 |
||||||
|
50 |
||||||
|
50 |
||||||
|
50 |
||||||
|
50 |
||||||
|
50 |
||||||
|
50 |
||||||
|
50 |
||||||
@ -0,0 +1,56 @@ |
|||||||
|
--TEST-- |
||||||
|
Test log() - basic function test log() |
||||||
|
--INI-- |
||||||
|
precision=14 |
||||||
|
--FILE-- |
||||||
|
<?php |
||||||
|
$values = array(23, |
||||||
|
-23, |
||||||
|
2.345e1, |
||||||
|
-2.345e1, |
||||||
|
0x17, |
||||||
|
027, |
||||||
|
"23", |
||||||
|
"23.45", |
||||||
|
"2.345e1", |
||||||
|
true, |
||||||
|
false); |
||||||
|
|
||||||
|
echo "\n LOG tests...no base\n"; |
||||||
|
for ($i = 0; $i < count($values); $i++) { |
||||||
|
$res = log($values[$i]); |
||||||
|
var_dump($res); |
||||||
|
} |
||||||
|
|
||||||
|
echo "\n LOG tests...base\n"; |
||||||
|
for ($i = 0; $i < count($values); $i++) { |
||||||
|
$res = log($values[$i], 4); |
||||||
|
var_dump($res); |
||||||
|
} |
||||||
|
?> |
||||||
|
--EXPECT-- |
||||||
|
LOG tests...no base |
||||||
|
float(3.1354942159291497) |
||||||
|
float(NAN) |
||||||
|
float(3.1548704948922883) |
||||||
|
float(NAN) |
||||||
|
float(3.1354942159291497) |
||||||
|
float(3.1354942159291497) |
||||||
|
float(3.1354942159291497) |
||||||
|
float(3.1548704948922883) |
||||||
|
float(3.1548704948922883) |
||||||
|
float(0) |
||||||
|
float(-INF) |
||||||
|
|
||||||
|
LOG tests...base |
||||||
|
float(2.2617809780285065) |
||||||
|
float(NAN) |
||||||
|
float(2.275758008814007) |
||||||
|
float(NAN) |
||||||
|
float(2.2617809780285065) |
||||||
|
float(2.2617809780285065) |
||||||
|
float(2.2617809780285065) |
||||||
|
float(2.275758008814007) |
||||||
|
float(2.275758008814007) |
||||||
|
float(0) |
||||||
|
float(-INF) |
||||||
@ -0,0 +1,135 @@ |
|||||||
|
--TEST-- |
||||||
|
Test number_format() - basic function test number_format() |
||||||
|
--FILE-- |
||||||
|
<?php |
||||||
|
$values = array(1234.5678, |
||||||
|
-1234.5678, |
||||||
|
1234.6578e4, |
||||||
|
-1234.56789e4, |
||||||
|
999999, |
||||||
|
-999999, |
||||||
|
999999.0, |
||||||
|
-999999.0, |
||||||
|
0x1234CDEF, |
||||||
|
02777777777, |
||||||
|
"123456789", |
||||||
|
"123.456789", |
||||||
|
"12.3456789e1", |
||||||
|
true, |
||||||
|
false); |
||||||
|
|
||||||
|
echo "\n number_format tests.....default\n"; |
||||||
|
for ($i = 0; $i < count($values); $i++) { |
||||||
|
$res = number_format($values[$i]); |
||||||
|
var_dump($res); |
||||||
|
} |
||||||
|
|
||||||
|
echo "\n number_format tests.....with two dp\n"; |
||||||
|
for ($i = 0; $i < count($values); $i++) { |
||||||
|
$res = number_format($values[$i], 2); |
||||||
|
var_dump($res); |
||||||
|
} |
||||||
|
|
||||||
|
echo "\n number_format tests.....English format\n"; |
||||||
|
for ($i = 0; $i < count($values); $i++) { |
||||||
|
$res = number_format($values[$i], 2, '.', ' '); |
||||||
|
var_dump($res); |
||||||
|
} |
||||||
|
|
||||||
|
echo "\n number_format tests.....French format\n"; |
||||||
|
for ($i = 0; $i < count($values); $i++) { |
||||||
|
$res = number_format($values[$i], 2, ',' , ' '); |
||||||
|
var_dump($res); |
||||||
|
} |
||||||
|
|
||||||
|
echo "\n number_format tests.....multichar format\n"; |
||||||
|
for ($i = 0; $i < count($values); $i++) { |
||||||
|
$res = number_format($values[$i], 2, ' DECIMALS ' , ' THOUSAND '); |
||||||
|
var_dump($res); |
||||||
|
} |
||||||
|
?> |
||||||
|
--EXPECT-- |
||||||
|
number_format tests.....default |
||||||
|
string(5) "1,235" |
||||||
|
string(6) "-1,235" |
||||||
|
string(10) "12,346,578" |
||||||
|
string(11) "-12,345,679" |
||||||
|
string(7) "999,999" |
||||||
|
string(8) "-999,999" |
||||||
|
string(7) "999,999" |
||||||
|
string(8) "-999,999" |
||||||
|
string(11) "305,450,479" |
||||||
|
string(11) "402,653,183" |
||||||
|
string(11) "123,456,789" |
||||||
|
string(3) "123" |
||||||
|
string(3) "123" |
||||||
|
string(1) "1" |
||||||
|
string(1) "0" |
||||||
|
|
||||||
|
number_format tests.....with two dp |
||||||
|
string(8) "1,234.57" |
||||||
|
string(9) "-1,234.57" |
||||||
|
string(13) "12,346,578.00" |
||||||
|
string(14) "-12,345,678.90" |
||||||
|
string(10) "999,999.00" |
||||||
|
string(11) "-999,999.00" |
||||||
|
string(10) "999,999.00" |
||||||
|
string(11) "-999,999.00" |
||||||
|
string(14) "305,450,479.00" |
||||||
|
string(14) "402,653,183.00" |
||||||
|
string(14) "123,456,789.00" |
||||||
|
string(6) "123.46" |
||||||
|
string(6) "123.46" |
||||||
|
string(4) "1.00" |
||||||
|
string(4) "0.00" |
||||||
|
|
||||||
|
number_format tests.....English format |
||||||
|
string(8) "1 234.57" |
||||||
|
string(9) "-1 234.57" |
||||||
|
string(13) "12 346 578.00" |
||||||
|
string(14) "-12 345 678.90" |
||||||
|
string(10) "999 999.00" |
||||||
|
string(11) "-999 999.00" |
||||||
|
string(10) "999 999.00" |
||||||
|
string(11) "-999 999.00" |
||||||
|
string(14) "305 450 479.00" |
||||||
|
string(14) "402 653 183.00" |
||||||
|
string(14) "123 456 789.00" |
||||||
|
string(6) "123.46" |
||||||
|
string(6) "123.46" |
||||||
|
string(4) "1.00" |
||||||
|
string(4) "0.00" |
||||||
|
|
||||||
|
number_format tests.....French format |
||||||
|
string(8) "1 234,57" |
||||||
|
string(9) "-1 234,57" |
||||||
|
string(13) "12 346 578,00" |
||||||
|
string(14) "-12 345 678,90" |
||||||
|
string(10) "999 999,00" |
||||||
|
string(11) "-999 999,00" |
||||||
|
string(10) "999 999,00" |
||||||
|
string(11) "-999 999,00" |
||||||
|
string(14) "305 450 479,00" |
||||||
|
string(14) "402 653 183,00" |
||||||
|
string(14) "123 456 789,00" |
||||||
|
string(6) "123,46" |
||||||
|
string(6) "123,46" |
||||||
|
string(4) "1,00" |
||||||
|
string(4) "0,00" |
||||||
|
|
||||||
|
number_format tests.....multichar format |
||||||
|
string(26) "1 THOUSAND 234 DECIMALS 57" |
||||||
|
string(27) "-1 THOUSAND 234 DECIMALS 57" |
||||||
|
string(40) "12 THOUSAND 346 THOUSAND 578 DECIMALS 00" |
||||||
|
string(41) "-12 THOUSAND 345 THOUSAND 678 DECIMALS 90" |
||||||
|
string(28) "999 THOUSAND 999 DECIMALS 00" |
||||||
|
string(29) "-999 THOUSAND 999 DECIMALS 00" |
||||||
|
string(28) "999 THOUSAND 999 DECIMALS 00" |
||||||
|
string(29) "-999 THOUSAND 999 DECIMALS 00" |
||||||
|
string(41) "305 THOUSAND 450 THOUSAND 479 DECIMALS 00" |
||||||
|
string(41) "402 THOUSAND 653 THOUSAND 183 DECIMALS 00" |
||||||
|
string(41) "123 THOUSAND 456 THOUSAND 789 DECIMALS 00" |
||||||
|
string(15) "123 DECIMALS 46" |
||||||
|
string(15) "123 DECIMALS 46" |
||||||
|
string(13) "1 DECIMALS 00" |
||||||
|
string(13) "0 DECIMALS 00" |
||||||
@ -0,0 +1,305 @@ |
|||||||
|
--TEST-- |
||||||
|
Test number_format() - test function with different decimal places |
||||||
|
--FILE-- |
||||||
|
<?php |
||||||
|
|
||||||
|
define("MAX_INT32", 2147483647); |
||||||
|
define("MIN_INT32", -2147483647 - 1); |
||||||
|
|
||||||
|
$values = array( |
||||||
|
1.5151, |
||||||
|
15.151, |
||||||
|
151.51, |
||||||
|
1515.1, |
||||||
|
15151, |
||||||
|
-1.5151, |
||||||
|
-15.151, |
||||||
|
-151.51, |
||||||
|
-1515.1, |
||||||
|
-15151, |
||||||
|
999, |
||||||
|
-999, |
||||||
|
999.0, |
||||||
|
-999.0, |
||||||
|
999999, |
||||||
|
-999999, |
||||||
|
999999.0, |
||||||
|
-999999.0, |
||||||
|
MAX_INT32, |
||||||
|
MIN_INT32, |
||||||
|
); |
||||||
|
|
||||||
|
$decimals = array(0, 1, 2, 3, 4, 5, -1, -2, -3, -4, -5, PHP_INT_MIN); |
||||||
|
|
||||||
|
foreach ($values as $value) { |
||||||
|
echo 'testing '; |
||||||
|
var_dump($value); |
||||||
|
|
||||||
|
foreach ($decimals as $decimal) { |
||||||
|
echo '... with decimal places of ' . $decimal . ': '; |
||||||
|
var_dump(number_format($value, $decimal)); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
?> |
||||||
|
--EXPECTF-- |
||||||
|
testing float(1.5151) |
||||||
|
... with decimal places of 0: string(1) "2" |
||||||
|
... with decimal places of 1: string(3) "1.5" |
||||||
|
... with decimal places of 2: string(4) "1.52" |
||||||
|
... with decimal places of 3: string(5) "1.515" |
||||||
|
... with decimal places of 4: string(6) "1.5151" |
||||||
|
... with decimal places of 5: string(7) "1.51510" |
||||||
|
... with decimal places of -1: string(1) "0" |
||||||
|
... with decimal places of -2: string(1) "0" |
||||||
|
... with decimal places of -3: string(1) "0" |
||||||
|
... with decimal places of -4: string(1) "0" |
||||||
|
... with decimal places of -5: string(1) "0" |
||||||
|
... with decimal places of %i: string(1) "0" |
||||||
|
testing float(15.151) |
||||||
|
... with decimal places of 0: string(2) "15" |
||||||
|
... with decimal places of 1: string(4) "15.2" |
||||||
|
... with decimal places of 2: string(5) "15.15" |
||||||
|
... with decimal places of 3: string(6) "15.151" |
||||||
|
... with decimal places of 4: string(7) "15.1510" |
||||||
|
... with decimal places of 5: string(8) "15.15100" |
||||||
|
... with decimal places of -1: string(2) "20" |
||||||
|
... with decimal places of -2: string(1) "0" |
||||||
|
... with decimal places of -3: string(1) "0" |
||||||
|
... with decimal places of -4: string(1) "0" |
||||||
|
... with decimal places of -5: string(1) "0" |
||||||
|
... with decimal places of %i: string(1) "0" |
||||||
|
testing float(151.51) |
||||||
|
... with decimal places of 0: string(3) "152" |
||||||
|
... with decimal places of 1: string(5) "151.5" |
||||||
|
... with decimal places of 2: string(6) "151.51" |
||||||
|
... with decimal places of 3: string(7) "151.510" |
||||||
|
... with decimal places of 4: string(8) "151.5100" |
||||||
|
... with decimal places of 5: string(9) "151.51000" |
||||||
|
... with decimal places of -1: string(3) "150" |
||||||
|
... with decimal places of -2: string(3) "200" |
||||||
|
... with decimal places of -3: string(1) "0" |
||||||
|
... with decimal places of -4: string(1) "0" |
||||||
|
... with decimal places of -5: string(1) "0" |
||||||
|
... with decimal places of %i: string(1) "0" |
||||||
|
testing float(1515.1) |
||||||
|
... with decimal places of 0: string(5) "1,515" |
||||||
|
... with decimal places of 1: string(7) "1,515.1" |
||||||
|
... with decimal places of 2: string(8) "1,515.10" |
||||||
|
... with decimal places of 3: string(9) "1,515.100" |
||||||
|
... with decimal places of 4: string(10) "1,515.1000" |
||||||
|
... with decimal places of 5: string(11) "1,515.10000" |
||||||
|
... with decimal places of -1: string(5) "1,520" |
||||||
|
... with decimal places of -2: string(5) "1,500" |
||||||
|
... with decimal places of -3: string(5) "2,000" |
||||||
|
... with decimal places of -4: string(1) "0" |
||||||
|
... with decimal places of -5: string(1) "0" |
||||||
|
... with decimal places of %i: string(1) "0" |
||||||
|
testing int(15151) |
||||||
|
... with decimal places of 0: string(6) "15,151" |
||||||
|
... with decimal places of 1: string(8) "15,151.0" |
||||||
|
... with decimal places of 2: string(9) "15,151.00" |
||||||
|
... with decimal places of 3: string(10) "15,151.000" |
||||||
|
... with decimal places of 4: string(11) "15,151.0000" |
||||||
|
... with decimal places of 5: string(12) "15,151.00000" |
||||||
|
... with decimal places of -1: string(6) "15,150" |
||||||
|
... with decimal places of -2: string(6) "15,200" |
||||||
|
... with decimal places of -3: string(6) "15,000" |
||||||
|
... with decimal places of -4: string(6) "20,000" |
||||||
|
... with decimal places of -5: string(1) "0" |
||||||
|
... with decimal places of %i: string(1) "0" |
||||||
|
testing float(-1.5151) |
||||||
|
... with decimal places of 0: string(2) "-2" |
||||||
|
... with decimal places of 1: string(4) "-1.5" |
||||||
|
... with decimal places of 2: string(5) "-1.52" |
||||||
|
... with decimal places of 3: string(6) "-1.515" |
||||||
|
... with decimal places of 4: string(7) "-1.5151" |
||||||
|
... with decimal places of 5: string(8) "-1.51510" |
||||||
|
... with decimal places of -1: string(1) "0" |
||||||
|
... with decimal places of -2: string(1) "0" |
||||||
|
... with decimal places of -3: string(1) "0" |
||||||
|
... with decimal places of -4: string(1) "0" |
||||||
|
... with decimal places of -5: string(1) "0" |
||||||
|
... with decimal places of %i: string(1) "0" |
||||||
|
testing float(-15.151) |
||||||
|
... with decimal places of 0: string(3) "-15" |
||||||
|
... with decimal places of 1: string(5) "-15.2" |
||||||
|
... with decimal places of 2: string(6) "-15.15" |
||||||
|
... with decimal places of 3: string(7) "-15.151" |
||||||
|
... with decimal places of 4: string(8) "-15.1510" |
||||||
|
... with decimal places of 5: string(9) "-15.15100" |
||||||
|
... with decimal places of -1: string(3) "-20" |
||||||
|
... with decimal places of -2: string(1) "0" |
||||||
|
... with decimal places of -3: string(1) "0" |
||||||
|
... with decimal places of -4: string(1) "0" |
||||||
|
... with decimal places of -5: string(1) "0" |
||||||
|
... with decimal places of %i: string(1) "0" |
||||||
|
testing float(-151.51) |
||||||
|
... with decimal places of 0: string(4) "-152" |
||||||
|
... with decimal places of 1: string(6) "-151.5" |
||||||
|
... with decimal places of 2: string(7) "-151.51" |
||||||
|
... with decimal places of 3: string(8) "-151.510" |
||||||
|
... with decimal places of 4: string(9) "-151.5100" |
||||||
|
... with decimal places of 5: string(10) "-151.51000" |
||||||
|
... with decimal places of -1: string(4) "-150" |
||||||
|
... with decimal places of -2: string(4) "-200" |
||||||
|
... with decimal places of -3: string(1) "0" |
||||||
|
... with decimal places of -4: string(1) "0" |
||||||
|
... with decimal places of -5: string(1) "0" |
||||||
|
... with decimal places of %i: string(1) "0" |
||||||
|
testing float(-1515.1) |
||||||
|
... with decimal places of 0: string(6) "-1,515" |
||||||
|
... with decimal places of 1: string(8) "-1,515.1" |
||||||
|
... with decimal places of 2: string(9) "-1,515.10" |
||||||
|
... with decimal places of 3: string(10) "-1,515.100" |
||||||
|
... with decimal places of 4: string(11) "-1,515.1000" |
||||||
|
... with decimal places of 5: string(12) "-1,515.10000" |
||||||
|
... with decimal places of -1: string(6) "-1,520" |
||||||
|
... with decimal places of -2: string(6) "-1,500" |
||||||
|
... with decimal places of -3: string(6) "-2,000" |
||||||
|
... with decimal places of -4: string(1) "0" |
||||||
|
... with decimal places of -5: string(1) "0" |
||||||
|
... with decimal places of %i: string(1) "0" |
||||||
|
testing int(-15151) |
||||||
|
... with decimal places of 0: string(7) "-15,151" |
||||||
|
... with decimal places of 1: string(9) "-15,151.0" |
||||||
|
... with decimal places of 2: string(10) "-15,151.00" |
||||||
|
... with decimal places of 3: string(11) "-15,151.000" |
||||||
|
... with decimal places of 4: string(12) "-15,151.0000" |
||||||
|
... with decimal places of 5: string(13) "-15,151.00000" |
||||||
|
... with decimal places of -1: string(7) "-15,150" |
||||||
|
... with decimal places of -2: string(7) "-15,200" |
||||||
|
... with decimal places of -3: string(7) "-15,000" |
||||||
|
... with decimal places of -4: string(7) "-20,000" |
||||||
|
... with decimal places of -5: string(1) "0" |
||||||
|
... with decimal places of %i: string(1) "0" |
||||||
|
testing int(999) |
||||||
|
... with decimal places of 0: string(3) "999" |
||||||
|
... with decimal places of 1: string(5) "999.0" |
||||||
|
... with decimal places of 2: string(6) "999.00" |
||||||
|
... with decimal places of 3: string(7) "999.000" |
||||||
|
... with decimal places of 4: string(8) "999.0000" |
||||||
|
... with decimal places of 5: string(9) "999.00000" |
||||||
|
... with decimal places of -1: string(5) "1,000" |
||||||
|
... with decimal places of -2: string(5) "1,000" |
||||||
|
... with decimal places of -3: string(5) "1,000" |
||||||
|
... with decimal places of -4: string(1) "0" |
||||||
|
... with decimal places of -5: string(1) "0" |
||||||
|
... with decimal places of %i: string(1) "0" |
||||||
|
testing int(-999) |
||||||
|
... with decimal places of 0: string(4) "-999" |
||||||
|
... with decimal places of 1: string(6) "-999.0" |
||||||
|
... with decimal places of 2: string(7) "-999.00" |
||||||
|
... with decimal places of 3: string(8) "-999.000" |
||||||
|
... with decimal places of 4: string(9) "-999.0000" |
||||||
|
... with decimal places of 5: string(10) "-999.00000" |
||||||
|
... with decimal places of -1: string(6) "-1,000" |
||||||
|
... with decimal places of -2: string(6) "-1,000" |
||||||
|
... with decimal places of -3: string(6) "-1,000" |
||||||
|
... with decimal places of -4: string(1) "0" |
||||||
|
... with decimal places of -5: string(1) "0" |
||||||
|
... with decimal places of %i: string(1) "0" |
||||||
|
testing float(999) |
||||||
|
... with decimal places of 0: string(3) "999" |
||||||
|
... with decimal places of 1: string(5) "999.0" |
||||||
|
... with decimal places of 2: string(6) "999.00" |
||||||
|
... with decimal places of 3: string(7) "999.000" |
||||||
|
... with decimal places of 4: string(8) "999.0000" |
||||||
|
... with decimal places of 5: string(9) "999.00000" |
||||||
|
... with decimal places of -1: string(5) "1,000" |
||||||
|
... with decimal places of -2: string(5) "1,000" |
||||||
|
... with decimal places of -3: string(5) "1,000" |
||||||
|
... with decimal places of -4: string(1) "0" |
||||||
|
... with decimal places of -5: string(1) "0" |
||||||
|
... with decimal places of %i: string(1) "0" |
||||||
|
testing float(-999) |
||||||
|
... with decimal places of 0: string(4) "-999" |
||||||
|
... with decimal places of 1: string(6) "-999.0" |
||||||
|
... with decimal places of 2: string(7) "-999.00" |
||||||
|
... with decimal places of 3: string(8) "-999.000" |
||||||
|
... with decimal places of 4: string(9) "-999.0000" |
||||||
|
... with decimal places of 5: string(10) "-999.00000" |
||||||
|
... with decimal places of -1: string(6) "-1,000" |
||||||
|
... with decimal places of -2: string(6) "-1,000" |
||||||
|
... with decimal places of -3: string(6) "-1,000" |
||||||
|
... with decimal places of -4: string(1) "0" |
||||||
|
... with decimal places of -5: string(1) "0" |
||||||
|
... with decimal places of %i: string(1) "0" |
||||||
|
testing int(999999) |
||||||
|
... with decimal places of 0: string(7) "999,999" |
||||||
|
... with decimal places of 1: string(9) "999,999.0" |
||||||
|
... with decimal places of 2: string(10) "999,999.00" |
||||||
|
... with decimal places of 3: string(11) "999,999.000" |
||||||
|
... with decimal places of 4: string(12) "999,999.0000" |
||||||
|
... with decimal places of 5: string(13) "999,999.00000" |
||||||
|
... with decimal places of -1: string(9) "1,000,000" |
||||||
|
... with decimal places of -2: string(9) "1,000,000" |
||||||
|
... with decimal places of -3: string(9) "1,000,000" |
||||||
|
... with decimal places of -4: string(9) "1,000,000" |
||||||
|
... with decimal places of -5: string(9) "1,000,000" |
||||||
|
... with decimal places of %i: string(1) "0" |
||||||
|
testing int(-999999) |
||||||
|
... with decimal places of 0: string(8) "-999,999" |
||||||
|
... with decimal places of 1: string(10) "-999,999.0" |
||||||
|
... with decimal places of 2: string(11) "-999,999.00" |
||||||
|
... with decimal places of 3: string(12) "-999,999.000" |
||||||
|
... with decimal places of 4: string(13) "-999,999.0000" |
||||||
|
... with decimal places of 5: string(14) "-999,999.00000" |
||||||
|
... with decimal places of -1: string(10) "-1,000,000" |
||||||
|
... with decimal places of -2: string(10) "-1,000,000" |
||||||
|
... with decimal places of -3: string(10) "-1,000,000" |
||||||
|
... with decimal places of -4: string(10) "-1,000,000" |
||||||
|
... with decimal places of -5: string(10) "-1,000,000" |
||||||
|
... with decimal places of %i: string(1) "0" |
||||||
|
testing float(999999) |
||||||
|
... with decimal places of 0: string(7) "999,999" |
||||||
|
... with decimal places of 1: string(9) "999,999.0" |
||||||
|
... with decimal places of 2: string(10) "999,999.00" |
||||||
|
... with decimal places of 3: string(11) "999,999.000" |
||||||
|
... with decimal places of 4: string(12) "999,999.0000" |
||||||
|
... with decimal places of 5: string(13) "999,999.00000" |
||||||
|
... with decimal places of -1: string(9) "1,000,000" |
||||||
|
... with decimal places of -2: string(9) "1,000,000" |
||||||
|
... with decimal places of -3: string(9) "1,000,000" |
||||||
|
... with decimal places of -4: string(9) "1,000,000" |
||||||
|
... with decimal places of -5: string(9) "1,000,000" |
||||||
|
... with decimal places of %i: string(1) "0" |
||||||
|
testing float(-999999) |
||||||
|
... with decimal places of 0: string(8) "-999,999" |
||||||
|
... with decimal places of 1: string(10) "-999,999.0" |
||||||
|
... with decimal places of 2: string(11) "-999,999.00" |
||||||
|
... with decimal places of 3: string(12) "-999,999.000" |
||||||
|
... with decimal places of 4: string(13) "-999,999.0000" |
||||||
|
... with decimal places of 5: string(14) "-999,999.00000" |
||||||
|
... with decimal places of -1: string(10) "-1,000,000" |
||||||
|
... with decimal places of -2: string(10) "-1,000,000" |
||||||
|
... with decimal places of -3: string(10) "-1,000,000" |
||||||
|
... with decimal places of -4: string(10) "-1,000,000" |
||||||
|
... with decimal places of -5: string(10) "-1,000,000" |
||||||
|
... with decimal places of %i: string(1) "0" |
||||||
|
testing int(2147483647) |
||||||
|
... with decimal places of 0: string(13) "2,147,483,647" |
||||||
|
... with decimal places of 1: string(15) "2,147,483,647.0" |
||||||
|
... with decimal places of 2: string(16) "2,147,483,647.00" |
||||||
|
... with decimal places of 3: string(17) "2,147,483,647.000" |
||||||
|
... with decimal places of 4: string(18) "2,147,483,647.0000" |
||||||
|
... with decimal places of 5: string(19) "2,147,483,647.00000" |
||||||
|
... with decimal places of -1: string(13) "2,147,483,650" |
||||||
|
... with decimal places of -2: string(13) "2,147,483,600" |
||||||
|
... with decimal places of -3: string(13) "2,147,484,000" |
||||||
|
... with decimal places of -4: string(13) "2,147,480,000" |
||||||
|
... with decimal places of -5: string(13) "2,147,500,000" |
||||||
|
... with decimal places of %i: string(1) "0" |
||||||
|
testing int(-2147483648) |
||||||
|
... with decimal places of 0: string(14) "-2,147,483,648" |
||||||
|
... with decimal places of 1: string(16) "-2,147,483,648.0" |
||||||
|
... with decimal places of 2: string(17) "-2,147,483,648.00" |
||||||
|
... with decimal places of 3: string(18) "-2,147,483,648.000" |
||||||
|
... with decimal places of 4: string(19) "-2,147,483,648.0000" |
||||||
|
... with decimal places of 5: string(20) "-2,147,483,648.00000" |
||||||
|
... with decimal places of -1: string(14) "-2,147,483,650" |
||||||
|
... with decimal places of -2: string(14) "-2,147,483,600" |
||||||
|
... with decimal places of -3: string(14) "-2,147,484,000" |
||||||
|
... with decimal places of -4: string(14) "-2,147,480,000" |
||||||
|
... with decimal places of -5: string(14) "-2,147,500,000" |
||||||
|
... with decimal places of %i: string(1) "0" |
||||||
@ -0,0 +1,73 @@ |
|||||||
|
--TEST-- |
||||||
|
Test number_format() - multiple character separator support |
||||||
|
--FILE-- |
||||||
|
<?php |
||||||
|
$values = array(1234.5678, |
||||||
|
-1234.5678, |
||||||
|
1234.6578e4, |
||||||
|
-1234.56789e4, |
||||||
|
0x1234CDEF, |
||||||
|
02777777777, |
||||||
|
"123456789", |
||||||
|
"123.456789", |
||||||
|
"12.3456789e1", |
||||||
|
true, |
||||||
|
false); |
||||||
|
|
||||||
|
echo " number_format tests.....multiple character decimal point\n"; |
||||||
|
for ($i = 0; $i < count($values); $i++) { |
||||||
|
$res = number_format($values[$i], 2, '·', ' '); |
||||||
|
var_dump($res); |
||||||
|
} |
||||||
|
|
||||||
|
echo "\n number_format tests.....multiple character thousand separator\n"; |
||||||
|
for ($i = 0; $i < count($values); $i++) { |
||||||
|
$res = number_format($values[$i], 2, '.' , ' '); |
||||||
|
var_dump($res); |
||||||
|
} |
||||||
|
|
||||||
|
echo "\n number_format tests.....multiple character decimal and thousep\n"; |
||||||
|
for ($i = 0; $i < count($values); $i++) { |
||||||
|
$res = number_format($values[$i], 2, '·' , ' '); |
||||||
|
var_dump($res); |
||||||
|
} |
||||||
|
?> |
||||||
|
--EXPECT-- |
||||||
|
number_format tests.....multiple character decimal point |
||||||
|
string(13) "1 234·57" |
||||||
|
string(14) "-1 234·57" |
||||||
|
string(18) "12 346 578·00" |
||||||
|
string(19) "-12 345 678·90" |
||||||
|
string(19) "305 450 479·00" |
||||||
|
string(19) "402 653 183·00" |
||||||
|
string(19) "123 456 789·00" |
||||||
|
string(11) "123·46" |
||||||
|
string(11) "123·46" |
||||||
|
string(9) "1·00" |
||||||
|
string(9) "0·00" |
||||||
|
|
||||||
|
number_format tests.....multiple character thousand separator |
||||||
|
string(15) "1 234.57" |
||||||
|
string(16) "-1 234.57" |
||||||
|
string(27) "12 346 578.00" |
||||||
|
string(28) "-12 345 678.90" |
||||||
|
string(28) "305 450 479.00" |
||||||
|
string(28) "402 653 183.00" |
||||||
|
string(28) "123 456 789.00" |
||||||
|
string(6) "123.46" |
||||||
|
string(6) "123.46" |
||||||
|
string(4) "1.00" |
||||||
|
string(4) "0.00" |
||||||
|
|
||||||
|
number_format tests.....multiple character decimal and thousep |
||||||
|
string(20) "1 234·57" |
||||||
|
string(21) "-1 234·57" |
||||||
|
string(32) "12 346 578·00" |
||||||
|
string(33) "-12 345 678·90" |
||||||
|
string(33) "305 450 479·00" |
||||||
|
string(33) "402 653 183·00" |
||||||
|
string(33) "123 456 789·00" |
||||||
|
string(11) "123·46" |
||||||
|
string(11) "123·46" |
||||||
|
string(9) "1·00" |
||||||
|
string(9) "0·00" |
||||||
@ -0,0 +1,16 @@ |
|||||||
|
--TEST-- |
||||||
|
Prevent number_format from returning negative zero |
||||||
|
--FILE-- |
||||||
|
<?php |
||||||
|
|
||||||
|
$number = -1.15E-15; |
||||||
|
|
||||||
|
var_dump($number); |
||||||
|
var_dump(number_format($number, 2)); |
||||||
|
var_dump(number_format(-0.01, 2)); |
||||||
|
|
||||||
|
?> |
||||||
|
--EXPECT-- |
||||||
|
float(-1.15E-15) |
||||||
|
string(4) "0.00" |
||||||
|
string(5) "-0.01" |
||||||
@ -0,0 +1,12 @@ |
|||||||
|
--TEST-- |
||||||
|
number_format should use default thousands seperator when 3 arguments are used |
||||||
|
--FILE-- |
||||||
|
<?php |
||||||
|
|
||||||
|
$number = 2020.1415; |
||||||
|
|
||||||
|
var_dump(number_format($number, 2, 'F')); |
||||||
|
|
||||||
|
?> |
||||||
|
--EXPECT-- |
||||||
|
string(8) "2,020F14" |
||||||
@ -0,0 +1,14 @@ |
|||||||
|
--TEST-- |
||||||
|
number_format should use default values when passed null |
||||||
|
--FILE-- |
||||||
|
<?php |
||||||
|
|
||||||
|
$number = 2020.1415; |
||||||
|
|
||||||
|
var_dump(number_format($number, 2, null, 'T')); |
||||||
|
var_dump(number_format($number, 2, 'F', null)); |
||||||
|
|
||||||
|
?> |
||||||
|
--EXPECT-- |
||||||
|
string(8) "2T020.14" |
||||||
|
string(8) "2,020F14" |
||||||
@ -0,0 +1,134 @@ |
|||||||
|
--TEST-- |
||||||
|
Test octdec() function : usage variations - different data types as $octal_string arg |
||||||
|
--INI-- |
||||||
|
precision=14 |
||||||
|
--FILE-- |
||||||
|
<?php |
||||||
|
echo "*** Testing octdec() : usage variations ***\n"; |
||||||
|
|
||||||
|
// heredoc string |
||||||
|
$heredoc = <<<EOT |
||||||
|
abc |
||||||
|
xyz |
||||||
|
EOT; |
||||||
|
|
||||||
|
// get a resource variable |
||||||
|
$fp = fopen(__FILE__, "r"); |
||||||
|
|
||||||
|
$inputs = array( |
||||||
|
// int data |
||||||
|
/*1*/ 0, |
||||||
|
1, |
||||||
|
12345, |
||||||
|
-2345, |
||||||
|
4294967295, // largest decimal |
||||||
|
4294967296, |
||||||
|
|
||||||
|
// float data |
||||||
|
/*7*/ 10.5, |
||||||
|
-10.5, |
||||||
|
12.3456789000e10, |
||||||
|
12.3456789000E-10, |
||||||
|
.5, |
||||||
|
|
||||||
|
// boolean data |
||||||
|
/*14*/ true, |
||||||
|
false, |
||||||
|
TRUE, |
||||||
|
FALSE, |
||||||
|
|
||||||
|
// empty data |
||||||
|
/*18*/ "", |
||||||
|
'', |
||||||
|
array(), |
||||||
|
|
||||||
|
// string data |
||||||
|
/*21*/ "abcxyz", |
||||||
|
'abcxyz', |
||||||
|
$heredoc, |
||||||
|
|
||||||
|
// resource variable |
||||||
|
/*26*/ $fp |
||||||
|
); |
||||||
|
|
||||||
|
// loop through each element of $inputs to check the behaviour of octdec() |
||||||
|
$iterator = 1; |
||||||
|
foreach($inputs as $input) { |
||||||
|
echo "\n-- Iteration $iterator --\n"; |
||||||
|
try { |
||||||
|
var_dump(octdec($input)); |
||||||
|
} catch (TypeError $e) { |
||||||
|
echo $e->getMessage(), "\n"; |
||||||
|
} |
||||||
|
$iterator++; |
||||||
|
}; |
||||||
|
fclose($fp); |
||||||
|
?> |
||||||
|
--EXPECTF-- |
||||||
|
*** Testing octdec() : usage variations *** |
||||||
|
|
||||||
|
-- Iteration 1 -- |
||||||
|
int(0) |
||||||
|
|
||||||
|
-- Iteration 2 -- |
||||||
|
int(1) |
||||||
|
|
||||||
|
-- Iteration 3 -- |
||||||
|
int(5349) |
||||||
|
|
||||||
|
-- Iteration 4 -- |
||||||
|
int(1253) |
||||||
|
|
||||||
|
-- Iteration 5 -- |
||||||
|
int(1134037) |
||||||
|
|
||||||
|
-- Iteration 6 -- |
||||||
|
int(1134038) |
||||||
|
|
||||||
|
-- Iteration 7 -- |
||||||
|
int(69) |
||||||
|
|
||||||
|
-- Iteration 8 -- |
||||||
|
int(69) |
||||||
|
|
||||||
|
-- Iteration 9 -- |
||||||
|
int(175304192) |
||||||
|
|
||||||
|
-- Iteration 10 -- |
||||||
|
int(342391) |
||||||
|
|
||||||
|
-- Iteration 11 -- |
||||||
|
int(5) |
||||||
|
|
||||||
|
-- Iteration 12 -- |
||||||
|
int(1) |
||||||
|
|
||||||
|
-- Iteration 13 -- |
||||||
|
int(0) |
||||||
|
|
||||||
|
-- Iteration 14 -- |
||||||
|
int(1) |
||||||
|
|
||||||
|
-- Iteration 15 -- |
||||||
|
int(0) |
||||||
|
|
||||||
|
-- Iteration 16 -- |
||||||
|
int(0) |
||||||
|
|
||||||
|
-- Iteration 17 -- |
||||||
|
int(0) |
||||||
|
|
||||||
|
-- Iteration 18 -- |
||||||
|
octdec(): Argument #1 ($octal_string) must be of type string, array given |
||||||
|
|
||||||
|
-- Iteration 19 -- |
||||||
|
int(0) |
||||||
|
|
||||||
|
-- Iteration 20 -- |
||||||
|
int(0) |
||||||
|
|
||||||
|
-- Iteration 21 -- |
||||||
|
int(0) |
||||||
|
|
||||||
|
-- Iteration 22 -- |
||||||
|
octdec(): Argument #1 ($octal_string) must be of type string, resource given |
||||||
@ -0,0 +1,16 @@ |
|||||||
|
--TEST-- |
||||||
|
Test octdec() function : strange literals |
||||||
|
--FILE-- |
||||||
|
<?php |
||||||
|
|
||||||
|
var_dump(octdec('0o')); |
||||||
|
var_dump(octdec('0O')); |
||||||
|
var_dump(octdec('0')); |
||||||
|
var_dump(octdec('')); |
||||||
|
|
||||||
|
?> |
||||||
|
--EXPECT-- |
||||||
|
int(0) |
||||||
|
int(0) |
||||||
|
int(0) |
||||||
|
int(0) |
||||||
@ -0,0 +1,14 @@ |
|||||||
|
--TEST-- |
||||||
|
Test pi() - basic function test pi() |
||||||
|
--INI-- |
||||||
|
precision=17 |
||||||
|
--FILE-- |
||||||
|
<?php |
||||||
|
echo pi(), "\n"; |
||||||
|
echo M_PI, "\n"; |
||||||
|
// N.B pi() ignores all specified arguments no error |
||||||
|
// messages are produced if arguments are spcified. |
||||||
|
?> |
||||||
|
--EXPECT-- |
||||||
|
3.1415926535897931 |
||||||
|
3.1415926535897931 |
||||||
Loading…
Reference in new issue