1--TEST-- 2Test sprintf() function : usage variations - scientific formats with float values 3--FILE-- 4<?php 5/* Prototype : string sprintf(string $format [, mixed $arg1 [, mixed ...]]) 6 * Description: Return a formatted string 7 * Source code: ext/standard/formatted_print.c 8*/ 9 10echo "*** Testing sprintf() : scientific formats with float values ***\n"; 11 12// array of float values 13$float_values = array( 14 -2147483649, 15 2147483648, 16 -0x80000001, // float value, beyond max negative int 17 0x800000001, // float value, beyond max positive int 18 020000000001, // float value, beyond max positive int 19 -020000000001, // float value, beyond max negative int 20 0.0, 21 -0.1, 22 1.0, 23 1e5, 24 -1e5, 25 -1e5, 26 +1e5, 27 1e+5, 28 -1e-5, 29 1E8, 30 -1E9, 31 10.0000000000000000005, 32 10.5e+5 33); 34 35// array of scientific formats 36$scientific_formats = array( 37 "%e", "%he", "%le", 38 "%Le", " %e", "%e ", 39 "\t%e", "\n%e", "%4e", 40 "%30e", "%[0-1]", "%*e" 41); 42 43 44$count = 1; 45foreach($float_values as $float_value) { 46 echo "\n-- Iteration $count --\n"; 47 48 foreach($scientific_formats as $format) { 49 var_dump( sprintf($format, $float_value) ); 50 } 51 $count++; 52}; 53 54echo "Done"; 55?> 56--EXPECT-- 57*** Testing sprintf() : scientific formats with float values *** 58 59-- Iteration 1 -- 60string(12) "-2.147484e+9" 61string(1) "e" 62string(12) "-2.147484e+9" 63string(1) "e" 64string(13) " -2.147484e+9" 65string(13) "-2.147484e+9 " 66string(13) " -2.147484e+9" 67string(13) " 68-2.147484e+9" 69string(12) "-2.147484e+9" 70string(30) " -2.147484e+9" 71string(4) "0-1]" 72string(1) "e" 73 74-- Iteration 2 -- 75string(11) "2.147484e+9" 76string(1) "e" 77string(11) "2.147484e+9" 78string(1) "e" 79string(12) " 2.147484e+9" 80string(12) "2.147484e+9 " 81string(12) " 2.147484e+9" 82string(12) " 832.147484e+9" 84string(11) "2.147484e+9" 85string(30) " 2.147484e+9" 86string(4) "0-1]" 87string(1) "e" 88 89-- Iteration 3 -- 90string(12) "-2.147484e+9" 91string(1) "e" 92string(12) "-2.147484e+9" 93string(1) "e" 94string(13) " -2.147484e+9" 95string(13) "-2.147484e+9 " 96string(13) " -2.147484e+9" 97string(13) " 98-2.147484e+9" 99string(12) "-2.147484e+9" 100string(30) " -2.147484e+9" 101string(4) "0-1]" 102string(1) "e" 103 104-- Iteration 4 -- 105string(12) "3.435974e+10" 106string(1) "e" 107string(12) "3.435974e+10" 108string(1) "e" 109string(13) " 3.435974e+10" 110string(13) "3.435974e+10 " 111string(13) " 3.435974e+10" 112string(13) " 1133.435974e+10" 114string(12) "3.435974e+10" 115string(30) " 3.435974e+10" 116string(4) "0-1]" 117string(1) "e" 118 119-- Iteration 5 -- 120string(11) "2.147484e+9" 121string(1) "e" 122string(11) "2.147484e+9" 123string(1) "e" 124string(12) " 2.147484e+9" 125string(12) "2.147484e+9 " 126string(12) " 2.147484e+9" 127string(12) " 1282.147484e+9" 129string(11) "2.147484e+9" 130string(30) " 2.147484e+9" 131string(4) "0-1]" 132string(1) "e" 133 134-- Iteration 6 -- 135string(12) "-2.147484e+9" 136string(1) "e" 137string(12) "-2.147484e+9" 138string(1) "e" 139string(13) " -2.147484e+9" 140string(13) "-2.147484e+9 " 141string(13) " -2.147484e+9" 142string(13) " 143-2.147484e+9" 144string(12) "-2.147484e+9" 145string(30) " -2.147484e+9" 146string(4) "0-1]" 147string(1) "e" 148 149-- Iteration 7 -- 150string(11) "0.000000e+0" 151string(1) "e" 152string(11) "0.000000e+0" 153string(1) "e" 154string(12) " 0.000000e+0" 155string(12) "0.000000e+0 " 156string(12) " 0.000000e+0" 157string(12) " 1580.000000e+0" 159string(11) "0.000000e+0" 160string(30) " 0.000000e+0" 161string(4) "0-1]" 162string(1) "e" 163 164-- Iteration 8 -- 165string(12) "-1.000000e-1" 166string(1) "e" 167string(12) "-1.000000e-1" 168string(1) "e" 169string(13) " -1.000000e-1" 170string(13) "-1.000000e-1 " 171string(13) " -1.000000e-1" 172string(13) " 173-1.000000e-1" 174string(12) "-1.000000e-1" 175string(30) " -1.000000e-1" 176string(4) "0-1]" 177string(1) "e" 178 179-- Iteration 9 -- 180string(11) "1.000000e+0" 181string(1) "e" 182string(11) "1.000000e+0" 183string(1) "e" 184string(12) " 1.000000e+0" 185string(12) "1.000000e+0 " 186string(12) " 1.000000e+0" 187string(12) " 1881.000000e+0" 189string(11) "1.000000e+0" 190string(30) " 1.000000e+0" 191string(4) "0-1]" 192string(1) "e" 193 194-- Iteration 10 -- 195string(11) "1.000000e+5" 196string(1) "e" 197string(11) "1.000000e+5" 198string(1) "e" 199string(12) " 1.000000e+5" 200string(12) "1.000000e+5 " 201string(12) " 1.000000e+5" 202string(12) " 2031.000000e+5" 204string(11) "1.000000e+5" 205string(30) " 1.000000e+5" 206string(4) "0-1]" 207string(1) "e" 208 209-- Iteration 11 -- 210string(12) "-1.000000e+5" 211string(1) "e" 212string(12) "-1.000000e+5" 213string(1) "e" 214string(13) " -1.000000e+5" 215string(13) "-1.000000e+5 " 216string(13) " -1.000000e+5" 217string(13) " 218-1.000000e+5" 219string(12) "-1.000000e+5" 220string(30) " -1.000000e+5" 221string(4) "0-1]" 222string(1) "e" 223 224-- Iteration 12 -- 225string(12) "-1.000000e+5" 226string(1) "e" 227string(12) "-1.000000e+5" 228string(1) "e" 229string(13) " -1.000000e+5" 230string(13) "-1.000000e+5 " 231string(13) " -1.000000e+5" 232string(13) " 233-1.000000e+5" 234string(12) "-1.000000e+5" 235string(30) " -1.000000e+5" 236string(4) "0-1]" 237string(1) "e" 238 239-- Iteration 13 -- 240string(11) "1.000000e+5" 241string(1) "e" 242string(11) "1.000000e+5" 243string(1) "e" 244string(12) " 1.000000e+5" 245string(12) "1.000000e+5 " 246string(12) " 1.000000e+5" 247string(12) " 2481.000000e+5" 249string(11) "1.000000e+5" 250string(30) " 1.000000e+5" 251string(4) "0-1]" 252string(1) "e" 253 254-- Iteration 14 -- 255string(11) "1.000000e+5" 256string(1) "e" 257string(11) "1.000000e+5" 258string(1) "e" 259string(12) " 1.000000e+5" 260string(12) "1.000000e+5 " 261string(12) " 1.000000e+5" 262string(12) " 2631.000000e+5" 264string(11) "1.000000e+5" 265string(30) " 1.000000e+5" 266string(4) "0-1]" 267string(1) "e" 268 269-- Iteration 15 -- 270string(12) "-1.000000e-5" 271string(1) "e" 272string(12) "-1.000000e-5" 273string(1) "e" 274string(13) " -1.000000e-5" 275string(13) "-1.000000e-5 " 276string(13) " -1.000000e-5" 277string(13) " 278-1.000000e-5" 279string(12) "-1.000000e-5" 280string(30) " -1.000000e-5" 281string(4) "0-1]" 282string(1) "e" 283 284-- Iteration 16 -- 285string(11) "1.000000e+8" 286string(1) "e" 287string(11) "1.000000e+8" 288string(1) "e" 289string(12) " 1.000000e+8" 290string(12) "1.000000e+8 " 291string(12) " 1.000000e+8" 292string(12) " 2931.000000e+8" 294string(11) "1.000000e+8" 295string(30) " 1.000000e+8" 296string(4) "0-1]" 297string(1) "e" 298 299-- Iteration 17 -- 300string(12) "-1.000000e+9" 301string(1) "e" 302string(12) "-1.000000e+9" 303string(1) "e" 304string(13) " -1.000000e+9" 305string(13) "-1.000000e+9 " 306string(13) " -1.000000e+9" 307string(13) " 308-1.000000e+9" 309string(12) "-1.000000e+9" 310string(30) " -1.000000e+9" 311string(4) "0-1]" 312string(1) "e" 313 314-- Iteration 18 -- 315string(11) "1.000000e+1" 316string(1) "e" 317string(11) "1.000000e+1" 318string(1) "e" 319string(12) " 1.000000e+1" 320string(12) "1.000000e+1 " 321string(12) " 1.000000e+1" 322string(12) " 3231.000000e+1" 324string(11) "1.000000e+1" 325string(30) " 1.000000e+1" 326string(4) "0-1]" 327string(1) "e" 328 329-- Iteration 19 -- 330string(11) "1.050000e+6" 331string(1) "e" 332string(11) "1.050000e+6" 333string(1) "e" 334string(12) " 1.050000e+6" 335string(12) "1.050000e+6 " 336string(12) " 1.050000e+6" 337string(12) " 3381.050000e+6" 339string(11) "1.050000e+6" 340string(30) " 1.050000e+6" 341string(4) "0-1]" 342string(1) "e" 343Done 344