1--TEST--
2Testing floatval() and its alias doubleval() functions : usage variations - different data types as $y arg
3--FILE--
4<?php
5/* Prototype: float floatval( mixed $var );
6 * Description: Returns the float value of var.
7 */
8
9
10
11// get a resource type variable
12$fp = fopen (__FILE__, "r");
13fclose($fp);
14$dfp = opendir ( dirname(__FILE__) );
15closedir($dfp);
16
17// other types in an array
18$not_float_types = array (
19           "-2147483648" => -2147483648, // max negative integer value
20           "2147483647" => 2147483648,  // max positive integer value
21           "file resoruce" => $fp,
22           "directory resource" => $dfp,
23           "\"0.0\"" => "0.0", // string
24           "\"1.0\"" => "1.0",
25	       "\"-1.3e3\"" => "-1.3e3",
26		   "\"bob-1.3e3\"" => "bob-1.3e3",
27           "\"10 Some dollars\"" => "10 Some dollars",
28	       "\"10.2 Some Dollars\"" => "10.2 Some Dollars",
29	       "\"10.0 dollar\" + 1" => "10.0 dollar" + 1,
30		   "\"10.0 dollar\" + 1.0" => "10.0 dollar" + 1.0,
31           "\"\"" => "",
32           "true" => true,
33           "NULL" => NULL,
34           "null" => null,
35                 );
36/* loop through the $not_float_types to see working of
37   floatval() on non float types, expected output: float value valid floating point numbers */
38echo "\n*** Testing floatval() on non floating types ***\n";
39foreach ($not_float_types as $key => $type ) {
40   echo "\n-- Iteration : $key --\n";
41   var_dump( floatval($type) );
42}
43
44echo "\n*** Testing doubleval() on non floating types ***\n";
45
46/* loop through the $not_float_types to see working of
47   doubleval() on non float types, expected output: float value valid floating point numbers */
48foreach ($not_float_types as $key => $type ) {
49   echo "\n-- Iteration : $key --\n";
50   var_dump( doubleval($type) );
51}
52?>
53===DONE===
54--EXPECTF--
55*** Testing floatval() on non floating types ***
56
57-- Iteration : -2147483648 --
58float(-2147483648)
59
60-- Iteration : 2147483647 --
61float(2147483648)
62
63-- Iteration : file resoruce --
64float(%d)
65
66-- Iteration : directory resource --
67float(%d)
68
69-- Iteration : "0.0" --
70float(0)
71
72-- Iteration : "1.0" --
73float(1)
74
75-- Iteration : "-1.3e3" --
76float(-1300)
77
78-- Iteration : "bob-1.3e3" --
79float(0)
80
81-- Iteration : "10 Some dollars" --
82float(10)
83
84-- Iteration : "10.2 Some Dollars" --
85float(10.2)
86
87-- Iteration : "10.0 dollar" + 1 --
88float(11)
89
90-- Iteration : "10.0 dollar" + 1.0 --
91float(11)
92
93-- Iteration : "" --
94float(0)
95
96-- Iteration : true --
97float(1)
98
99-- Iteration : NULL --
100float(0)
101
102-- Iteration : null --
103float(0)
104
105*** Testing doubleval() on non floating types ***
106
107-- Iteration : -2147483648 --
108float(-2147483648)
109
110-- Iteration : 2147483647 --
111float(2147483648)
112
113-- Iteration : file resoruce --
114float(%d)
115
116-- Iteration : directory resource --
117float(%d)
118
119-- Iteration : "0.0" --
120float(0)
121
122-- Iteration : "1.0" --
123float(1)
124
125-- Iteration : "-1.3e3" --
126float(-1300)
127
128-- Iteration : "bob-1.3e3" --
129float(0)
130
131-- Iteration : "10 Some dollars" --
132float(10)
133
134-- Iteration : "10.2 Some Dollars" --
135float(10.2)
136
137-- Iteration : "10.0 dollar" + 1 --
138float(11)
139
140-- Iteration : "10.0 dollar" + 1.0 --
141float(11)
142
143-- Iteration : "" --
144float(0)
145
146-- Iteration : true --
147float(1)
148
149-- Iteration : NULL --
150float(0)
151
152-- Iteration : null --
153float(0)
154===DONE===