summaryrefslogtreecommitdiff
path: root/ext/standard/tests/general_functions/floatval.phpt
blob: a01e01dbf1743f3cb75f67a54b392ac011a1da45 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
--TEST--
Testing floatval() and its alias doubleval() Functions
--FILE--
<?php
/* Prototype: float floatval( mixed $var );
 * Description: Returns the float value of var.
 */

echo "*** Testing floatval() with valid float values ***\n";
// different valid  float values
$valid_floats = array(
                0.0,
                1.0,
                -1.0,
                1.234,
 	        -1.234,
                1.2e3,
	        -1.2e3,
		10.0000000000000000005,
		10.5e+5,
                1e5,
	        -1e5,
                1e-5,
		-1e-1,
		1e+5,
		-1e+5,
		1E5,
		-1E5,
		1E+5,
		-1E+5,
		.5e+7,
		-.5e+7
);

/* loop to check that floatval() recognizes different
   float values, expected output:float value for valid floating point number */

foreach ($valid_floats as $value ) {
   var_dump( floatval($value) );
}


echo "\n*** Testing doubleval() with valid float values ***\n";
/* loop to check that doubleval() also recognizes different
   float values, expected output:float value for valid floating point number */

foreach ($valid_floats as $value ) {
   var_dump( doubleval($value) );
}


echo "\n*** Testing floatval() on non floating types ***\n";

// get a resource type variable
$fp = fopen (__FILE__, "r");
fclose($fp);
$dfp = opendir ( __DIR__ );
closedir($dfp);

// other types in an array
$not_float_types = array (
                   -2147483648, // max negative integer value
                   2147483648,  // max positive integer value
                   $fp,  // resource
                   $dfp,
                   "0.0", // string
                   "1.0",
	           "-1.3e3",
		   "bob-1.3e3",
                   "10 Some dollars",
	           "10.2 Some Dollars",
	       	   "10.0 dollar" + 1,
		   "10.0 dollar" + 1.0,
                   "",
                   true,
                   NULL,
                   null,
                 );
/* loop through the $not_float_types to see working of
   floatval() on non float types, expected output: float value valid floating point numbers */
foreach ($not_float_types as $type ) {
   var_dump( floatval($type) );
}


echo "\n*** Testing doubleval() on non floating types ***\n";

/* loop through the $not_float_types to see working of
   doubleval() on non float types, expected output: float value valid floating point numbers */
foreach ($not_float_types as $type ) {
   var_dump( doubleval($type) );
}




echo "\n*** Testing error conditions ***\n";
//Zero argument
var_dump( floatval() );
var_dump( doubleval() );

//arguments more than expected
var_dump( floatval(TRUE, FALSE) );
var_dump( doubleval(TRUE, FALSE) );

echo "\nDone\n";


?>
--EXPECTF--
*** Testing floatval() with valid float values ***
float(0)
float(1)
float(-1)
float(1.234)
float(-1.234)
float(1200)
float(-1200)
float(10)
float(1050000)
float(100000)
float(-100000)
float(1.0E-5)
float(-0.1)
float(100000)
float(-100000)
float(100000)
float(-100000)
float(100000)
float(-100000)
float(5000000)
float(-5000000)

*** Testing doubleval() with valid float values ***
float(0)
float(1)
float(-1)
float(1.234)
float(-1.234)
float(1200)
float(-1200)
float(10)
float(1050000)
float(100000)
float(-100000)
float(1.0E-5)
float(-0.1)
float(100000)
float(-100000)
float(100000)
float(-100000)
float(100000)
float(-100000)
float(5000000)
float(-5000000)

*** Testing floatval() on non floating types ***

Notice: A non well formed numeric value encountered in %s on line 69

Notice: A non well formed numeric value encountered in %s on line 70
float(-2147483648)
float(2147483648)
float(%d)
float(%d)
float(0)
float(1)
float(-1300)
float(0)
float(10)
float(10.2)
float(11)
float(11)
float(0)
float(1)
float(0)
float(0)

*** Testing doubleval() on non floating types ***
float(-2147483648)
float(2147483648)
float(%d)
float(%d)
float(0)
float(1)
float(-1300)
float(0)
float(10)
float(10.2)
float(11)
float(11)
float(0)
float(1)
float(0)
float(0)

*** Testing error conditions ***

Warning: floatval() expects exactly 1 parameter, 0 given in %s on line %d
NULL

Warning: doubleval() expects exactly 1 parameter, 0 given in %s on line %d
NULL

Warning: floatval() expects exactly 1 parameter, 2 given in %s on line %d
NULL

Warning: doubleval() expects exactly 1 parameter, 2 given in %s on line %d
NULL

Done