summaryrefslogtreecommitdiff
path: root/ext/standard/tests/general_functions/floatval_basic.phpt
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@baserock.org>2013-03-14 05:42:27 +0000
committer <>2013-04-03 16:25:08 +0000
commitc4dd7a1a684490673e25aaf4fabec5df138854c4 (patch)
tree4d57c44caae4480efff02b90b9be86f44bf25409 /ext/standard/tests/general_functions/floatval_basic.phpt
downloadphp2-master.tar.gz
Imported from /home/lorry/working-area/delta_php2/php-5.4.13.tar.bz2.HEADphp-5.4.13master
Diffstat (limited to 'ext/standard/tests/general_functions/floatval_basic.phpt')
-rw-r--r--ext/standard/tests/general_functions/floatval_basic.phpt172
1 files changed, 172 insertions, 0 deletions
diff --git a/ext/standard/tests/general_functions/floatval_basic.phpt b/ext/standard/tests/general_functions/floatval_basic.phpt
new file mode 100644
index 0000000..129aa87
--- /dev/null
+++ b/ext/standard/tests/general_functions/floatval_basic.phpt
@@ -0,0 +1,172 @@
+--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=== \ No newline at end of file