1--TEST-- 2Test sprintf() function : usage variations - float formats with float values 3--FILE-- 4<?php 5echo "*** Testing sprintf() : float formats with float values ***\n"; 6 7// array of float type values 8 9$float_values = array ( 10-2147483649, // float value 11 2147483648, // float value 12 -0x80000001, // float value, beyond max negative int 13 0x800000001, // float value, beyond max positive int 14 020000000001, // float value, beyond max positive int 15 -020000000001, // float value, beyond max negative int 16 0.0, 17 -0.1, 18 10.0000000000000000005, 19 10.5e+5, 20 1e5, 21 -1e5, 22 1e-5, 23 -1e-5, 24 1e+5, 25 -1e+5, 26 1E5, 27 -1E5, 28 1E+5, 29 -1E+5, 30 1E-5, 31 -1E-5, 32 .5e+7, 33 -.5e+7, 34 .6e-19, 35 -.6e-19, 36 .05E+44, 37 -.05E+44, 38 .0034E-30, 39 -.0034E-30 40); 41 42// various float formats 43$float_formats = array( 44 "%f", "%lf", " %f", "%f ", 45 "\t%f", "\n%f", "%4f", "%30f", 46); 47 48$count = 1; 49foreach($float_values as $float_value) { 50 echo "\n-- Iteration $count --\n"; 51 52 foreach($float_formats as $format) { 53 var_dump( sprintf($format, $float_value) ); 54 } 55 $count++; 56}; 57 58echo "Done"; 59?> 60--EXPECT-- 61*** Testing sprintf() : float formats with float values *** 62 63-- Iteration 1 -- 64string(18) "-2147483649.000000" 65string(18) "-2147483649.000000" 66string(19) " -2147483649.000000" 67string(19) "-2147483649.000000 " 68string(19) " -2147483649.000000" 69string(19) " 70-2147483649.000000" 71string(18) "-2147483649.000000" 72string(30) " -2147483649.000000" 73 74-- Iteration 2 -- 75string(17) "2147483648.000000" 76string(17) "2147483648.000000" 77string(18) " 2147483648.000000" 78string(18) "2147483648.000000 " 79string(18) " 2147483648.000000" 80string(18) " 812147483648.000000" 82string(17) "2147483648.000000" 83string(30) " 2147483648.000000" 84 85-- Iteration 3 -- 86string(18) "-2147483649.000000" 87string(18) "-2147483649.000000" 88string(19) " -2147483649.000000" 89string(19) "-2147483649.000000 " 90string(19) " -2147483649.000000" 91string(19) " 92-2147483649.000000" 93string(18) "-2147483649.000000" 94string(30) " -2147483649.000000" 95 96-- Iteration 4 -- 97string(18) "34359738369.000000" 98string(18) "34359738369.000000" 99string(19) " 34359738369.000000" 100string(19) "34359738369.000000 " 101string(19) " 34359738369.000000" 102string(19) " 10334359738369.000000" 104string(18) "34359738369.000000" 105string(30) " 34359738369.000000" 106 107-- Iteration 5 -- 108string(17) "2147483649.000000" 109string(17) "2147483649.000000" 110string(18) " 2147483649.000000" 111string(18) "2147483649.000000 " 112string(18) " 2147483649.000000" 113string(18) " 1142147483649.000000" 115string(17) "2147483649.000000" 116string(30) " 2147483649.000000" 117 118-- Iteration 6 -- 119string(18) "-2147483649.000000" 120string(18) "-2147483649.000000" 121string(19) " -2147483649.000000" 122string(19) "-2147483649.000000 " 123string(19) " -2147483649.000000" 124string(19) " 125-2147483649.000000" 126string(18) "-2147483649.000000" 127string(30) " -2147483649.000000" 128 129-- Iteration 7 -- 130string(8) "0.000000" 131string(8) "0.000000" 132string(9) " 0.000000" 133string(9) "0.000000 " 134string(9) " 0.000000" 135string(9) " 1360.000000" 137string(8) "0.000000" 138string(30) " 0.000000" 139 140-- Iteration 8 -- 141string(9) "-0.100000" 142string(9) "-0.100000" 143string(10) " -0.100000" 144string(10) "-0.100000 " 145string(10) " -0.100000" 146string(10) " 147-0.100000" 148string(9) "-0.100000" 149string(30) " -0.100000" 150 151-- Iteration 9 -- 152string(9) "10.000000" 153string(9) "10.000000" 154string(10) " 10.000000" 155string(10) "10.000000 " 156string(10) " 10.000000" 157string(10) " 15810.000000" 159string(9) "10.000000" 160string(30) " 10.000000" 161 162-- Iteration 10 -- 163string(14) "1050000.000000" 164string(14) "1050000.000000" 165string(15) " 1050000.000000" 166string(15) "1050000.000000 " 167string(15) " 1050000.000000" 168string(15) " 1691050000.000000" 170string(14) "1050000.000000" 171string(30) " 1050000.000000" 172 173-- Iteration 11 -- 174string(13) "100000.000000" 175string(13) "100000.000000" 176string(14) " 100000.000000" 177string(14) "100000.000000 " 178string(14) " 100000.000000" 179string(14) " 180100000.000000" 181string(13) "100000.000000" 182string(30) " 100000.000000" 183 184-- Iteration 12 -- 185string(14) "-100000.000000" 186string(14) "-100000.000000" 187string(15) " -100000.000000" 188string(15) "-100000.000000 " 189string(15) " -100000.000000" 190string(15) " 191-100000.000000" 192string(14) "-100000.000000" 193string(30) " -100000.000000" 194 195-- Iteration 13 -- 196string(8) "0.000010" 197string(8) "0.000010" 198string(9) " 0.000010" 199string(9) "0.000010 " 200string(9) " 0.000010" 201string(9) " 2020.000010" 203string(8) "0.000010" 204string(30) " 0.000010" 205 206-- Iteration 14 -- 207string(9) "-0.000010" 208string(9) "-0.000010" 209string(10) " -0.000010" 210string(10) "-0.000010 " 211string(10) " -0.000010" 212string(10) " 213-0.000010" 214string(9) "-0.000010" 215string(30) " -0.000010" 216 217-- Iteration 15 -- 218string(13) "100000.000000" 219string(13) "100000.000000" 220string(14) " 100000.000000" 221string(14) "100000.000000 " 222string(14) " 100000.000000" 223string(14) " 224100000.000000" 225string(13) "100000.000000" 226string(30) " 100000.000000" 227 228-- Iteration 16 -- 229string(14) "-100000.000000" 230string(14) "-100000.000000" 231string(15) " -100000.000000" 232string(15) "-100000.000000 " 233string(15) " -100000.000000" 234string(15) " 235-100000.000000" 236string(14) "-100000.000000" 237string(30) " -100000.000000" 238 239-- Iteration 17 -- 240string(13) "100000.000000" 241string(13) "100000.000000" 242string(14) " 100000.000000" 243string(14) "100000.000000 " 244string(14) " 100000.000000" 245string(14) " 246100000.000000" 247string(13) "100000.000000" 248string(30) " 100000.000000" 249 250-- Iteration 18 -- 251string(14) "-100000.000000" 252string(14) "-100000.000000" 253string(15) " -100000.000000" 254string(15) "-100000.000000 " 255string(15) " -100000.000000" 256string(15) " 257-100000.000000" 258string(14) "-100000.000000" 259string(30) " -100000.000000" 260 261-- Iteration 19 -- 262string(13) "100000.000000" 263string(13) "100000.000000" 264string(14) " 100000.000000" 265string(14) "100000.000000 " 266string(14) " 100000.000000" 267string(14) " 268100000.000000" 269string(13) "100000.000000" 270string(30) " 100000.000000" 271 272-- Iteration 20 -- 273string(14) "-100000.000000" 274string(14) "-100000.000000" 275string(15) " -100000.000000" 276string(15) "-100000.000000 " 277string(15) " -100000.000000" 278string(15) " 279-100000.000000" 280string(14) "-100000.000000" 281string(30) " -100000.000000" 282 283-- Iteration 21 -- 284string(8) "0.000010" 285string(8) "0.000010" 286string(9) " 0.000010" 287string(9) "0.000010 " 288string(9) " 0.000010" 289string(9) " 2900.000010" 291string(8) "0.000010" 292string(30) " 0.000010" 293 294-- Iteration 22 -- 295string(9) "-0.000010" 296string(9) "-0.000010" 297string(10) " -0.000010" 298string(10) "-0.000010 " 299string(10) " -0.000010" 300string(10) " 301-0.000010" 302string(9) "-0.000010" 303string(30) " -0.000010" 304 305-- Iteration 23 -- 306string(14) "5000000.000000" 307string(14) "5000000.000000" 308string(15) " 5000000.000000" 309string(15) "5000000.000000 " 310string(15) " 5000000.000000" 311string(15) " 3125000000.000000" 313string(14) "5000000.000000" 314string(30) " 5000000.000000" 315 316-- Iteration 24 -- 317string(15) "-5000000.000000" 318string(15) "-5000000.000000" 319string(16) " -5000000.000000" 320string(16) "-5000000.000000 " 321string(16) " -5000000.000000" 322string(16) " 323-5000000.000000" 324string(15) "-5000000.000000" 325string(30) " -5000000.000000" 326 327-- Iteration 25 -- 328string(8) "0.000000" 329string(8) "0.000000" 330string(9) " 0.000000" 331string(9) "0.000000 " 332string(9) " 0.000000" 333string(9) " 3340.000000" 335string(8) "0.000000" 336string(30) " 0.000000" 337 338-- Iteration 26 -- 339string(9) "-0.000000" 340string(9) "-0.000000" 341string(10) " -0.000000" 342string(10) "-0.000000 " 343string(10) " -0.000000" 344string(10) " 345-0.000000" 346string(9) "-0.000000" 347string(30) " -0.000000" 348 349-- Iteration 27 -- 350string(50) "5000000000000000069686058479707049565356032.000000" 351string(50) "5000000000000000069686058479707049565356032.000000" 352string(51) " 5000000000000000069686058479707049565356032.000000" 353string(51) "5000000000000000069686058479707049565356032.000000 " 354string(51) " 5000000000000000069686058479707049565356032.000000" 355string(51) " 3565000000000000000069686058479707049565356032.000000" 357string(50) "5000000000000000069686058479707049565356032.000000" 358string(50) "5000000000000000069686058479707049565356032.000000" 359 360-- Iteration 28 -- 361string(51) "-5000000000000000069686058479707049565356032.000000" 362string(51) "-5000000000000000069686058479707049565356032.000000" 363string(52) " -5000000000000000069686058479707049565356032.000000" 364string(52) "-5000000000000000069686058479707049565356032.000000 " 365string(52) " -5000000000000000069686058479707049565356032.000000" 366string(52) " 367-5000000000000000069686058479707049565356032.000000" 368string(51) "-5000000000000000069686058479707049565356032.000000" 369string(51) "-5000000000000000069686058479707049565356032.000000" 370 371-- Iteration 29 -- 372string(8) "0.000000" 373string(8) "0.000000" 374string(9) " 0.000000" 375string(9) "0.000000 " 376string(9) " 0.000000" 377string(9) " 3780.000000" 379string(8) "0.000000" 380string(30) " 0.000000" 381 382-- Iteration 30 -- 383string(9) "-0.000000" 384string(9) "-0.000000" 385string(10) " -0.000000" 386string(10) "-0.000000 " 387string(10) " -0.000000" 388string(10) " 389-0.000000" 390string(9) "-0.000000" 391string(30) " -0.000000" 392Done 393