1--TEST--
2Test fscanf() function: usage variations - scientific formats with float values
3--FILE--
4<?php
5
6/* Test fscanf() to scan float values using different scientific format types */
7
8$file_path = __DIR__;
9
10echo "*** Test fscanf(): different scientific format types with float values ***\n";
11
12// create a file
13$filename = "$file_path/fscanf_variation46.tmp";
14$file_handle = fopen($filename, "w");
15if($file_handle == false)
16  exit("Error:failed to open file $filename");
17
18// array of float type values
19
20$float_values = array (
21  -2147483649,
22  2147483648,
23  -0x80000001, // float value, beyond max negative int
24  0x800000001, // float value, beyond max positive int
25  020000000001, // float value, beyond max positive int
26  -020000000001, // float value, beyond max negative int
27  0.0,
28  -0.1,
29  1.0,
30  1e5,
31  -1e6,
32  1E8,
33  -1E9,
34  10.0000000000000000005,
35  10.5e+5
36);
37
38$scientific_formats = array( "%e", "%he", "%le", "%Le", " %e", "%e ", "% e", "\t%e", "\n%e", "%4e", "%30e", "%[0-9]", "%*e");
39
40$counter = 1;
41
42// writing to the file
43foreach($float_values as $value) {
44  @fprintf($file_handle, $value);
45  @fprintf($file_handle, "\n");
46}
47// closing the file
48fclose($file_handle);
49
50// opening the file for reading
51$file_handle = fopen($filename, "r");
52if($file_handle == false) {
53  exit("Error:failed to open file $filename");
54}
55
56$counter = 1;
57// reading the values from file using different scientific formats
58foreach($scientific_formats as $scientific_format) {
59  // rewind the file so that for every foreach iteration the file pointer starts from bof
60  rewind($file_handle);
61  echo "\n-- iteration $counter --\n";
62  while( !feof($file_handle) ) {
63    try {
64      var_dump(fscanf($file_handle,$scientific_format));
65    } catch (ValueError $exception) {
66      echo $exception->getMessage() . "\n";
67    }
68  }
69  $counter++;
70}
71
72echo "\n*** Done ***";
73?>
74--CLEAN--
75<?php
76$file_path = __DIR__;
77$filename = "$file_path/fscanf_variation46.tmp";
78unlink($filename);
79?>
80--EXPECT--
81*** Test fscanf(): different scientific format types with float values ***
82
83-- iteration 1 --
84array(1) {
85  [0]=>
86  float(-2147483649)
87}
88array(1) {
89  [0]=>
90  float(2147483648)
91}
92array(1) {
93  [0]=>
94  float(-2147483649)
95}
96array(1) {
97  [0]=>
98  float(34359738369)
99}
100array(1) {
101  [0]=>
102  float(2147483649)
103}
104array(1) {
105  [0]=>
106  float(-2147483649)
107}
108array(1) {
109  [0]=>
110  float(0)
111}
112array(1) {
113  [0]=>
114  float(-0.1)
115}
116array(1) {
117  [0]=>
118  float(1)
119}
120array(1) {
121  [0]=>
122  float(100000)
123}
124array(1) {
125  [0]=>
126  float(-1000000)
127}
128array(1) {
129  [0]=>
130  float(100000000)
131}
132array(1) {
133  [0]=>
134  float(-1000000000)
135}
136array(1) {
137  [0]=>
138  float(10)
139}
140array(1) {
141  [0]=>
142  float(1050000)
143}
144bool(false)
145
146-- iteration 2 --
147array(1) {
148  [0]=>
149  float(-2147483649)
150}
151array(1) {
152  [0]=>
153  float(2147483648)
154}
155array(1) {
156  [0]=>
157  float(-2147483649)
158}
159array(1) {
160  [0]=>
161  float(34359738369)
162}
163array(1) {
164  [0]=>
165  float(2147483649)
166}
167array(1) {
168  [0]=>
169  float(-2147483649)
170}
171array(1) {
172  [0]=>
173  float(0)
174}
175array(1) {
176  [0]=>
177  float(-0.1)
178}
179array(1) {
180  [0]=>
181  float(1)
182}
183array(1) {
184  [0]=>
185  float(100000)
186}
187array(1) {
188  [0]=>
189  float(-1000000)
190}
191array(1) {
192  [0]=>
193  float(100000000)
194}
195array(1) {
196  [0]=>
197  float(-1000000000)
198}
199array(1) {
200  [0]=>
201  float(10)
202}
203array(1) {
204  [0]=>
205  float(1050000)
206}
207bool(false)
208
209-- iteration 3 --
210array(1) {
211  [0]=>
212  float(-2147483649)
213}
214array(1) {
215  [0]=>
216  float(2147483648)
217}
218array(1) {
219  [0]=>
220  float(-2147483649)
221}
222array(1) {
223  [0]=>
224  float(34359738369)
225}
226array(1) {
227  [0]=>
228  float(2147483649)
229}
230array(1) {
231  [0]=>
232  float(-2147483649)
233}
234array(1) {
235  [0]=>
236  float(0)
237}
238array(1) {
239  [0]=>
240  float(-0.1)
241}
242array(1) {
243  [0]=>
244  float(1)
245}
246array(1) {
247  [0]=>
248  float(100000)
249}
250array(1) {
251  [0]=>
252  float(-1000000)
253}
254array(1) {
255  [0]=>
256  float(100000000)
257}
258array(1) {
259  [0]=>
260  float(-1000000000)
261}
262array(1) {
263  [0]=>
264  float(10)
265}
266array(1) {
267  [0]=>
268  float(1050000)
269}
270bool(false)
271
272-- iteration 4 --
273array(1) {
274  [0]=>
275  float(-2147483649)
276}
277array(1) {
278  [0]=>
279  float(2147483648)
280}
281array(1) {
282  [0]=>
283  float(-2147483649)
284}
285array(1) {
286  [0]=>
287  float(34359738369)
288}
289array(1) {
290  [0]=>
291  float(2147483649)
292}
293array(1) {
294  [0]=>
295  float(-2147483649)
296}
297array(1) {
298  [0]=>
299  float(0)
300}
301array(1) {
302  [0]=>
303  float(-0.1)
304}
305array(1) {
306  [0]=>
307  float(1)
308}
309array(1) {
310  [0]=>
311  float(100000)
312}
313array(1) {
314  [0]=>
315  float(-1000000)
316}
317array(1) {
318  [0]=>
319  float(100000000)
320}
321array(1) {
322  [0]=>
323  float(-1000000000)
324}
325array(1) {
326  [0]=>
327  float(10)
328}
329array(1) {
330  [0]=>
331  float(1050000)
332}
333bool(false)
334
335-- iteration 5 --
336array(1) {
337  [0]=>
338  float(-2147483649)
339}
340array(1) {
341  [0]=>
342  float(2147483648)
343}
344array(1) {
345  [0]=>
346  float(-2147483649)
347}
348array(1) {
349  [0]=>
350  float(34359738369)
351}
352array(1) {
353  [0]=>
354  float(2147483649)
355}
356array(1) {
357  [0]=>
358  float(-2147483649)
359}
360array(1) {
361  [0]=>
362  float(0)
363}
364array(1) {
365  [0]=>
366  float(-0.1)
367}
368array(1) {
369  [0]=>
370  float(1)
371}
372array(1) {
373  [0]=>
374  float(100000)
375}
376array(1) {
377  [0]=>
378  float(-1000000)
379}
380array(1) {
381  [0]=>
382  float(100000000)
383}
384array(1) {
385  [0]=>
386  float(-1000000000)
387}
388array(1) {
389  [0]=>
390  float(10)
391}
392array(1) {
393  [0]=>
394  float(1050000)
395}
396bool(false)
397
398-- iteration 6 --
399array(1) {
400  [0]=>
401  float(-2147483649)
402}
403array(1) {
404  [0]=>
405  float(2147483648)
406}
407array(1) {
408  [0]=>
409  float(-2147483649)
410}
411array(1) {
412  [0]=>
413  float(34359738369)
414}
415array(1) {
416  [0]=>
417  float(2147483649)
418}
419array(1) {
420  [0]=>
421  float(-2147483649)
422}
423array(1) {
424  [0]=>
425  float(0)
426}
427array(1) {
428  [0]=>
429  float(-0.1)
430}
431array(1) {
432  [0]=>
433  float(1)
434}
435array(1) {
436  [0]=>
437  float(100000)
438}
439array(1) {
440  [0]=>
441  float(-1000000)
442}
443array(1) {
444  [0]=>
445  float(100000000)
446}
447array(1) {
448  [0]=>
449  float(-1000000000)
450}
451array(1) {
452  [0]=>
453  float(10)
454}
455array(1) {
456  [0]=>
457  float(1050000)
458}
459bool(false)
460
461-- iteration 7 --
462Bad scan conversion character " "
463Bad scan conversion character " "
464Bad scan conversion character " "
465Bad scan conversion character " "
466Bad scan conversion character " "
467Bad scan conversion character " "
468Bad scan conversion character " "
469Bad scan conversion character " "
470Bad scan conversion character " "
471Bad scan conversion character " "
472Bad scan conversion character " "
473Bad scan conversion character " "
474Bad scan conversion character " "
475Bad scan conversion character " "
476Bad scan conversion character " "
477bool(false)
478
479-- iteration 8 --
480array(1) {
481  [0]=>
482  float(-2147483649)
483}
484array(1) {
485  [0]=>
486  float(2147483648)
487}
488array(1) {
489  [0]=>
490  float(-2147483649)
491}
492array(1) {
493  [0]=>
494  float(34359738369)
495}
496array(1) {
497  [0]=>
498  float(2147483649)
499}
500array(1) {
501  [0]=>
502  float(-2147483649)
503}
504array(1) {
505  [0]=>
506  float(0)
507}
508array(1) {
509  [0]=>
510  float(-0.1)
511}
512array(1) {
513  [0]=>
514  float(1)
515}
516array(1) {
517  [0]=>
518  float(100000)
519}
520array(1) {
521  [0]=>
522  float(-1000000)
523}
524array(1) {
525  [0]=>
526  float(100000000)
527}
528array(1) {
529  [0]=>
530  float(-1000000000)
531}
532array(1) {
533  [0]=>
534  float(10)
535}
536array(1) {
537  [0]=>
538  float(1050000)
539}
540bool(false)
541
542-- iteration 9 --
543array(1) {
544  [0]=>
545  float(-2147483649)
546}
547array(1) {
548  [0]=>
549  float(2147483648)
550}
551array(1) {
552  [0]=>
553  float(-2147483649)
554}
555array(1) {
556  [0]=>
557  float(34359738369)
558}
559array(1) {
560  [0]=>
561  float(2147483649)
562}
563array(1) {
564  [0]=>
565  float(-2147483649)
566}
567array(1) {
568  [0]=>
569  float(0)
570}
571array(1) {
572  [0]=>
573  float(-0.1)
574}
575array(1) {
576  [0]=>
577  float(1)
578}
579array(1) {
580  [0]=>
581  float(100000)
582}
583array(1) {
584  [0]=>
585  float(-1000000)
586}
587array(1) {
588  [0]=>
589  float(100000000)
590}
591array(1) {
592  [0]=>
593  float(-1000000000)
594}
595array(1) {
596  [0]=>
597  float(10)
598}
599array(1) {
600  [0]=>
601  float(1050000)
602}
603bool(false)
604
605-- iteration 10 --
606array(1) {
607  [0]=>
608  float(-214)
609}
610array(1) {
611  [0]=>
612  float(2147)
613}
614array(1) {
615  [0]=>
616  float(-214)
617}
618array(1) {
619  [0]=>
620  float(3435)
621}
622array(1) {
623  [0]=>
624  float(2147)
625}
626array(1) {
627  [0]=>
628  float(-214)
629}
630array(1) {
631  [0]=>
632  float(0)
633}
634array(1) {
635  [0]=>
636  float(-0.1)
637}
638array(1) {
639  [0]=>
640  float(1)
641}
642array(1) {
643  [0]=>
644  float(1000)
645}
646array(1) {
647  [0]=>
648  float(-100)
649}
650array(1) {
651  [0]=>
652  float(1000)
653}
654array(1) {
655  [0]=>
656  float(-100)
657}
658array(1) {
659  [0]=>
660  float(10)
661}
662array(1) {
663  [0]=>
664  float(1050)
665}
666bool(false)
667
668-- iteration 11 --
669array(1) {
670  [0]=>
671  float(-2147483649)
672}
673array(1) {
674  [0]=>
675  float(2147483648)
676}
677array(1) {
678  [0]=>
679  float(-2147483649)
680}
681array(1) {
682  [0]=>
683  float(34359738369)
684}
685array(1) {
686  [0]=>
687  float(2147483649)
688}
689array(1) {
690  [0]=>
691  float(-2147483649)
692}
693array(1) {
694  [0]=>
695  float(0)
696}
697array(1) {
698  [0]=>
699  float(-0.1)
700}
701array(1) {
702  [0]=>
703  float(1)
704}
705array(1) {
706  [0]=>
707  float(100000)
708}
709array(1) {
710  [0]=>
711  float(-1000000)
712}
713array(1) {
714  [0]=>
715  float(100000000)
716}
717array(1) {
718  [0]=>
719  float(-1000000000)
720}
721array(1) {
722  [0]=>
723  float(10)
724}
725array(1) {
726  [0]=>
727  float(1050000)
728}
729bool(false)
730
731-- iteration 12 --
732array(1) {
733  [0]=>
734  NULL
735}
736array(1) {
737  [0]=>
738  string(10) "2147483648"
739}
740array(1) {
741  [0]=>
742  NULL
743}
744array(1) {
745  [0]=>
746  string(11) "34359738369"
747}
748array(1) {
749  [0]=>
750  string(10) "2147483649"
751}
752array(1) {
753  [0]=>
754  NULL
755}
756array(1) {
757  [0]=>
758  string(1) "0"
759}
760array(1) {
761  [0]=>
762  NULL
763}
764array(1) {
765  [0]=>
766  string(1) "1"
767}
768array(1) {
769  [0]=>
770  string(6) "100000"
771}
772array(1) {
773  [0]=>
774  NULL
775}
776array(1) {
777  [0]=>
778  string(9) "100000000"
779}
780array(1) {
781  [0]=>
782  NULL
783}
784array(1) {
785  [0]=>
786  string(2) "10"
787}
788array(1) {
789  [0]=>
790  string(7) "1050000"
791}
792bool(false)
793
794-- iteration 13 --
795array(0) {
796}
797array(0) {
798}
799array(0) {
800}
801array(0) {
802}
803array(0) {
804}
805array(0) {
806}
807array(0) {
808}
809array(0) {
810}
811array(0) {
812}
813array(0) {
814}
815array(0) {
816}
817array(0) {
818}
819array(0) {
820}
821array(0) {
822}
823array(0) {
824}
825bool(false)
826
827*** Done ***
828