mirror of
https://github.com/php/php-src.git
synced 2025-08-19 17:04:47 +02:00

This patch adds missing newlines, trims multiple redundant final newlines into a single one, and trims redundant leading newlines in all *.phpt sections. According to POSIX, a line is a sequence of zero or more non-' <newline>' characters plus a terminating '<newline>' character. [1] Files should normally have at least one final newline character. C89 [2] and later standards [3] mention a final newline: "A source file that is not empty shall end in a new-line character, which shall not be immediately preceded by a backslash character." Although it is not mandatory for all files to have a final newline fixed, a more consistent and homogeneous approach brings less of commit differences issues and a better development experience in certain text editors and IDEs. [1] http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_206 [2] https://port70.net/~nsz/c/c89/c89-draft.html#2.1.1.2 [3] https://port70.net/~nsz/c/c99/n1256.html#5.1.1.2
172 lines
3 KiB
PHP
172 lines
3 KiB
PHP
--TEST--
|
|
Testing floatval() and its alias doubleval() Functions
|
|
--INI--
|
|
precision = 14
|
|
--FILE--
|
|
<?php
|
|
/* Prototype: float floatval( mixed $var );
|
|
* Description: Returns the float value of var.
|
|
*/
|
|
|
|
// different valid float values
|
|
$valid_floats = array(
|
|
"0.0" => 0.0,
|
|
"1.0" => 1.0,
|
|
"-1.0" => -1.0,
|
|
"1.234" => 1.234,
|
|
"-1.234" => -1.234,
|
|
"1.2e3" => 1.2e3,
|
|
"-1.2e3" => -1.2e3,
|
|
"10.0000000000000000005" => 10.0000000000000000005,
|
|
"10.5e+5" => 10.5e+5,
|
|
"1e5" => 1e5,
|
|
"-1e5" => -1e5,
|
|
"1e5" => 1e-5,
|
|
"-1e-1" => -1e-1,
|
|
"1e+5" => 1e+5,
|
|
"-1e+5" =>-1e+5,
|
|
"1E5" => 1E5,
|
|
"-1E5" => -1E5,
|
|
"1E+5" => 1E+5,
|
|
"-1E5" => -1E+5,
|
|
".5e+7" => .5e+7,
|
|
"-.5e+7" =>-.5e+7
|
|
);
|
|
|
|
/* loop to check that floatval() recognizes different
|
|
float values, expected output:float value for valid floating point number */
|
|
echo "*** Testing floatval() with valid float values ***\n";
|
|
foreach ($valid_floats as $key => $value ) {
|
|
echo "\n-- Iteration : $key -- \n";
|
|
var_dump( floatval($value) );
|
|
}
|
|
|
|
/* loop to check that doubleval() also recognizes different
|
|
float values, expected output:float value for valid floating point number */
|
|
echo "\n*** Testing doubleval() with valid float values ***\n";
|
|
foreach ($valid_floats as $key => $value ) {
|
|
echo "\n-- Iteration : $key -- \n";
|
|
var_dump( doubleval($value) );
|
|
}
|
|
|
|
?>
|
|
===DONE===
|
|
--EXPECT--
|
|
*** Testing floatval() with valid float values ***
|
|
|
|
-- Iteration : 0.0 --
|
|
float(0)
|
|
|
|
-- Iteration : 1.0 --
|
|
float(1)
|
|
|
|
-- Iteration : -1.0 --
|
|
float(-1)
|
|
|
|
-- Iteration : 1.234 --
|
|
float(1.234)
|
|
|
|
-- Iteration : -1.234 --
|
|
float(-1.234)
|
|
|
|
-- Iteration : 1.2e3 --
|
|
float(1200)
|
|
|
|
-- Iteration : -1.2e3 --
|
|
float(-1200)
|
|
|
|
-- Iteration : 10.0000000000000000005 --
|
|
float(10)
|
|
|
|
-- Iteration : 10.5e+5 --
|
|
float(1050000)
|
|
|
|
-- Iteration : 1e5 --
|
|
float(1.0E-5)
|
|
|
|
-- Iteration : -1e5 --
|
|
float(-100000)
|
|
|
|
-- Iteration : -1e-1 --
|
|
float(-0.1)
|
|
|
|
-- Iteration : 1e+5 --
|
|
float(100000)
|
|
|
|
-- Iteration : -1e+5 --
|
|
float(-100000)
|
|
|
|
-- Iteration : 1E5 --
|
|
float(100000)
|
|
|
|
-- Iteration : -1E5 --
|
|
float(-100000)
|
|
|
|
-- Iteration : 1E+5 --
|
|
float(100000)
|
|
|
|
-- Iteration : .5e+7 --
|
|
float(5000000)
|
|
|
|
-- Iteration : -.5e+7 --
|
|
float(-5000000)
|
|
|
|
*** Testing doubleval() with valid float values ***
|
|
|
|
-- Iteration : 0.0 --
|
|
float(0)
|
|
|
|
-- Iteration : 1.0 --
|
|
float(1)
|
|
|
|
-- Iteration : -1.0 --
|
|
float(-1)
|
|
|
|
-- Iteration : 1.234 --
|
|
float(1.234)
|
|
|
|
-- Iteration : -1.234 --
|
|
float(-1.234)
|
|
|
|
-- Iteration : 1.2e3 --
|
|
float(1200)
|
|
|
|
-- Iteration : -1.2e3 --
|
|
float(-1200)
|
|
|
|
-- Iteration : 10.0000000000000000005 --
|
|
float(10)
|
|
|
|
-- Iteration : 10.5e+5 --
|
|
float(1050000)
|
|
|
|
-- Iteration : 1e5 --
|
|
float(1.0E-5)
|
|
|
|
-- Iteration : -1e5 --
|
|
float(-100000)
|
|
|
|
-- Iteration : -1e-1 --
|
|
float(-0.1)
|
|
|
|
-- Iteration : 1e+5 --
|
|
float(100000)
|
|
|
|
-- Iteration : -1e+5 --
|
|
float(-100000)
|
|
|
|
-- Iteration : 1E5 --
|
|
float(100000)
|
|
|
|
-- Iteration : -1E5 --
|
|
float(-100000)
|
|
|
|
-- Iteration : 1E+5 --
|
|
float(100000)
|
|
|
|
-- Iteration : .5e+7 --
|
|
float(5000000)
|
|
|
|
-- Iteration : -.5e+7 --
|
|
float(-5000000)
|
|
===DONE===
|