1
0
mirror of https://github.com/php/php-src.git synced 2026-04-29 19:23:22 +02:00
Files
archived-php-src/ext/standard/tests/math/pow_variation2.phpt
T
Andrea Faulds 1e82ad8038 Warn about invalid strings in arithmetic
Squashed commit of the following:

commit e05d3b6732
Author: Andrea Faulds <ajf@ajf.me>
Date:   Wed Mar 30 01:43:35 2016 +0100

    UPGRADING and NEWS

commit 6caf1d4585
Author: Andrea Faulds <ajf@ajf.me>
Date:   Sun Mar 20 21:18:33 2016 +0000

    Fixes

commit 6dadb1b0ef
Author: Andrea Faulds <ajf@ajf.me>
Date:   Sun Feb 14 02:15:01 2016 +0000

    Add test for numeric string errors in assignment

commit bd5f04e8dd
Author: Andrea Faulds <ajf@ajf.me>
Date:   Sat Feb 13 23:53:05 2016 +0000

    Add test for numeric string errors

commit c72e92f16d
Author: Andrea Faulds <ajf@ajf.me>
Date:   Tue Jan 26 23:28:33 2016 +0000

    Add test for scientific notation in integer operations

commit d94c08852d
Author: Andrea Faulds <ajf@ajf.me>
Date:   Sun Feb 14 01:25:57 2016 +0000

    Disable optimiser evaluation for numeric string errors

commit 30ee954ed1
Author: Andrea Faulds <ajf@ajf.me>
Date:   Sun Feb 14 01:46:25 2016 +0000

    fixup

commit a6403b79e0
Author: Andrea Faulds <ajf@ajf.me>
Date:   Sat Feb 13 22:00:27 2016 +0000

    Do not convert error-causing numeric strings ahead-of-time

commit f9dc354014
Author: Andrea Faulds <ajf@ajf.me>
Date:   Sat Feb 13 19:15:38 2016 +0000

    Disable compile-time evaluation for numeric string errors

commit e05b0cc849
Author: Andrea Faulds <ajf@ajf.me>
Date:   Fri Feb 5 11:42:26 2016 +0000

    Make _zval_get_long_func_noisy function for inlining

commit 84d66321a5
Author: Andrea Faulds <ajf@ajf.me>
Date:   Tue Jan 26 23:10:00 2016 +0000

    Update tests

commit 5ac4a0cc4b
Author: Andrea Faulds <ajf@ajf.me>
Date:   Tue Jan 26 22:08:19 2016 +0000

    Use is_numeric_string_ex for zval_get_long etc.

commit c21f088485
Author: Andrea Faulds <ajf@ajf.me>
Date:   Thu Jan 7 21:13:04 2016 +0000

    Update tests

commit 63e214cf81
Author: Andrea Faulds <ajf@ajf.me>
Date:   Wed Jan 6 00:28:01 2016 +0000

    Warn on non-/bad numeric strings in arithmetic
2016-03-30 01:44:27 +01:00

183 lines
2.6 KiB
PHP

--TEST--
Test pow() function : usage variations - different data types as $exp argument
--INI--
precision = 14
--FILE--
<?php
/* Prototype : number pow ( number $base , number $exp )
* Description: Exponential expression.
* Source code: ext/standard/math.c
*/
echo "*** Testing pow() : usage variations ***\n";
//get an unset variable
$unset_var = 10;
unset ($unset_var);
// heredoc string
$heredoc = <<<EOT
abc
xyz
EOT;
// get a class
class classA
{
}
// get a resource variable
$fp = fopen(__FILE__, "r");
$inputs = array(
// int data
/*1*/ 0,
1,
12345,
-2345,
2147483647,
// float data
/*6*/ 2.5,
-2.5,
12.3456789000e10,
12.3456789000E-10,
.5,
// null data
/*11*/ NULL,
null,
// boolean data
/*13*/ true,
false,
TRUE,
FALSE,
// empty data
/*17*/ "",
'',
array(),
// string data
/*20*/ "abcxyz",
'abcxyz',
$heredoc,
// object data
/*23*/ new classA(),
// undefined data
/*24*/ @$undefined_var,
// unset data
/*25*/ @$unset_var,
// resource variable
/*26*/ $fp
);
// loop through each element of $inputs to check the behaviour of pow()
$iterator = 1;
foreach($inputs as $input) {
echo "\n-- Iteration $iterator --\n";
var_dump(pow(20.3, $input));
$iterator++;
};
fclose($fp);
?>
===Done===
--EXPECTF--
*** Testing pow() : usage variations ***
-- Iteration 1 --
float(1)
-- Iteration 2 --
float(20.3)
-- Iteration 3 --
float(INF)
-- Iteration 4 --
float(0)
-- Iteration 5 --
float(INF)
-- Iteration 6 --
float(1856.6929774279)
-- Iteration 7 --
float(0.00053859200856424)
-- Iteration 8 --
float(INF)
-- Iteration 9 --
float(1.0000000037168)
-- Iteration 10 --
float(4.5055521304275)
-- Iteration 11 --
float(1)
-- Iteration 12 --
float(1)
-- Iteration 13 --
float(20.3)
-- Iteration 14 --
float(1)
-- Iteration 15 --
float(20.3)
-- Iteration 16 --
float(1)
-- Iteration 17 --
Warning: A non-numeric value encountered in %s on line %d
float(1)
-- Iteration 18 --
Warning: A non-numeric value encountered in %s on line %d
float(1)
-- Iteration 19 --
int(1)
-- Iteration 20 --
Warning: A non-numeric value encountered in %s on line %d
float(1)
-- Iteration 21 --
Warning: A non-numeric value encountered in %s on line %d
float(1)
-- Iteration 22 --
Warning: A non-numeric value encountered in %s on line %d
float(1)
-- Iteration 23 --
Notice: Object of class classA could not be converted to int in %s on line %d
float(20.3)
-- Iteration 24 --
float(1)
-- Iteration 25 --
float(1)
-- Iteration 26 --
%s
===Done===