1--TEST-- 2Test sprintf() function : usage variations - unsigned formats with float values 3--SKIPIF-- 4<?php if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only"); ?> 5--FILE-- 6<?php 7/* Prototype : string sprintf(string $format [, mixed $arg1 [, mixed ...]]) 8 * Description: Return a formatted string 9 * Source code: ext/standard/formatted_print.c 10*/ 11 12echo "*** Testing sprintf() : unsigned formats with float values ***\n"; 13 14// array of float values 15$float_values = array( 16 2147483647, 17 0x800000001, // float value, beyond max positive int 18 020000000001, // float value, beyond max positive int 19 0.0, 20 -0.1, 21 1.0, 22 +1e5, 23 +5e+5, 24 +0e-5, 25 -1e5, 26 -1e+5, 27 -1e-2, 28 1e5, 29 1E8, 30 -1E9, 31 10.0000000000000000005, 32 10.5e+5 33); 34 35// array of unsigned formats 36$unsigned_formats = array( 37 "%u", "%hu", "%lu", 38 "%Lu", " %u", "%u ", 39 "\t%u", "\n%u", "%4u", 40 "%30u", "%[0-9]", "%*u" 41); 42 43$count = 1; 44foreach($float_values as $float_value) { 45 echo "\n-- Iteration $count --\n"; 46 47 foreach($unsigned_formats as $format) { 48 var_dump( sprintf($format, $float_value) ); 49 } 50 $count++; 51}; 52 53echo "Done"; 54?> 55--EXPECTF-- 56*** Testing sprintf() : unsigned formats with float values *** 57 58-- Iteration 1 -- 59string(10) "2147483647" 60string(1) "u" 61string(10) "2147483647" 62string(1) "u" 63string(11) " 2147483647" 64string(11) "2147483647 " 65string(11) " 2147483647" 66string(11) " 672147483647" 68string(10) "2147483647" 69string(30) " 2147483647" 70string(4) "0-9]" 71string(1) "u" 72 73-- Iteration 2 -- 74string(11) "34359738369" 75string(1) "u" 76string(11) "34359738369" 77string(1) "u" 78string(12) " 34359738369" 79string(12) "34359738369 " 80string(12) " 34359738369" 81string(12) " 8234359738369" 83string(11) "34359738369" 84string(30) " 34359738369" 85string(4) "0-9]" 86string(1) "u" 87 88-- Iteration 3 -- 89string(10) "2147483649" 90string(1) "u" 91string(10) "2147483649" 92string(1) "u" 93string(11) " 2147483649" 94string(11) "2147483649 " 95string(11) " 2147483649" 96string(11) " 972147483649" 98string(10) "2147483649" 99string(30) " 2147483649" 100string(4) "0-9]" 101string(1) "u" 102 103-- Iteration 4 -- 104string(1) "0" 105string(1) "u" 106string(1) "0" 107string(1) "u" 108string(2) " 0" 109string(2) "0 " 110string(2) " 0" 111string(2) " 1120" 113string(4) " 0" 114string(30) " 0" 115string(4) "0-9]" 116string(1) "u" 117 118-- Iteration 5 -- 119string(1) "0" 120string(1) "u" 121string(1) "0" 122string(1) "u" 123string(2) " 0" 124string(2) "0 " 125string(2) " 0" 126string(2) " 1270" 128string(4) " 0" 129string(30) " 0" 130string(4) "0-9]" 131string(1) "u" 132 133-- Iteration 6 -- 134string(1) "1" 135string(1) "u" 136string(1) "1" 137string(1) "u" 138string(2) " 1" 139string(2) "1 " 140string(2) " 1" 141string(2) " 1421" 143string(4) " 1" 144string(30) " 1" 145string(4) "0-9]" 146string(1) "u" 147 148-- Iteration 7 -- 149string(6) "100000" 150string(1) "u" 151string(6) "100000" 152string(1) "u" 153string(7) " 100000" 154string(7) "100000 " 155string(7) " 100000" 156string(7) " 157100000" 158string(6) "100000" 159string(30) " 100000" 160string(4) "0-9]" 161string(1) "u" 162 163-- Iteration 8 -- 164string(6) "500000" 165string(1) "u" 166string(6) "500000" 167string(1) "u" 168string(7) " 500000" 169string(7) "500000 " 170string(7) " 500000" 171string(7) " 172500000" 173string(6) "500000" 174string(30) " 500000" 175string(4) "0-9]" 176string(1) "u" 177 178-- Iteration 9 -- 179string(1) "0" 180string(1) "u" 181string(1) "0" 182string(1) "u" 183string(2) " 0" 184string(2) "0 " 185string(2) " 0" 186string(2) " 1870" 188string(4) " 0" 189string(30) " 0" 190string(4) "0-9]" 191string(1) "u" 192 193-- Iteration 10 -- 194string(20) "18446744073709451616" 195string(1) "u" 196string(20) "18446744073709451616" 197string(1) "u" 198string(21) " 18446744073709451616" 199string(21) "18446744073709451616 " 200string(21) " 18446744073709451616" 201string(21) " 20218446744073709451616" 203string(20) "18446744073709451616" 204string(30) " 18446744073709451616" 205string(4) "0-9]" 206string(1) "u" 207 208-- Iteration 11 -- 209string(20) "18446744073709451616" 210string(1) "u" 211string(20) "18446744073709451616" 212string(1) "u" 213string(21) " 18446744073709451616" 214string(21) "18446744073709451616 " 215string(21) " 18446744073709451616" 216string(21) " 21718446744073709451616" 218string(20) "18446744073709451616" 219string(30) " 18446744073709451616" 220string(4) "0-9]" 221string(1) "u" 222 223-- Iteration 12 -- 224string(1) "0" 225string(1) "u" 226string(1) "0" 227string(1) "u" 228string(2) " 0" 229string(2) "0 " 230string(2) " 0" 231string(2) " 2320" 233string(4) " 0" 234string(30) " 0" 235string(4) "0-9]" 236string(1) "u" 237 238-- Iteration 13 -- 239string(6) "100000" 240string(1) "u" 241string(6) "100000" 242string(1) "u" 243string(7) " 100000" 244string(7) "100000 " 245string(7) " 100000" 246string(7) " 247100000" 248string(6) "100000" 249string(30) " 100000" 250string(4) "0-9]" 251string(1) "u" 252 253-- Iteration 14 -- 254string(9) "100000000" 255string(1) "u" 256string(9) "100000000" 257string(1) "u" 258string(10) " 100000000" 259string(10) "100000000 " 260string(10) " 100000000" 261string(10) " 262100000000" 263string(9) "100000000" 264string(30) " 100000000" 265string(4) "0-9]" 266string(1) "u" 267 268-- Iteration 15 -- 269string(20) "18446744072709551616" 270string(1) "u" 271string(20) "18446744072709551616" 272string(1) "u" 273string(21) " 18446744072709551616" 274string(21) "18446744072709551616 " 275string(21) " 18446744072709551616" 276string(21) " 27718446744072709551616" 278string(20) "18446744072709551616" 279string(30) " 18446744072709551616" 280string(4) "0-9]" 281string(1) "u" 282 283-- Iteration 16 -- 284string(2) "10" 285string(1) "u" 286string(2) "10" 287string(1) "u" 288string(3) " 10" 289string(3) "10 " 290string(3) " 10" 291string(3) " 29210" 293string(4) " 10" 294string(30) " 10" 295string(4) "0-9]" 296string(1) "u" 297 298-- Iteration 17 -- 299string(7) "1050000" 300string(1) "u" 301string(7) "1050000" 302string(1) "u" 303string(8) " 1050000" 304string(8) "1050000 " 305string(8) " 1050000" 306string(8) " 3071050000" 308string(7) "1050000" 309string(30) " 1050000" 310string(4) "0-9]" 311string(1) "u" 312Done 313