1--TEST-- 2Test sprintf() function : usage variations - int 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() : integer formats with float values ***\n"; 13 14// array of float type values 15 16$float_values = array ( 17 2147483648, 18 0x800000001, // float value, beyond max positive int 19 020000000001, // float value, beyond max positive int 20 0.0, 21 -0.1, 22 1.0, 23 1e5, 24 -1e6, 25 1E8, 26 -1E9, 27 10.0000000000000000005, 28 10.5e+5 29); 30 31// various integer formats 32$int_formats = array( 33 "%d", "%hd", "%ld", 34 "%Ld", " %d", "%d ", 35 "\t%d", "\n%d", "%4d", 36 "%30d", "%[0-9]", "%*d" 37); 38 39$count = 1; 40foreach($float_values as $float_value) { 41 echo "\n-- Iteration $count --\n"; 42 43 foreach($int_formats as $format) { 44 var_dump( sprintf($format, $float_value) ); 45 } 46 $count++; 47}; 48 49echo "Done"; 50?> 51--EXPECTF-- 52*** Testing sprintf() : integer formats with float values *** 53 54-- Iteration 1 -- 55string(10) "2147483648" 56string(1) "d" 57string(10) "2147483648" 58string(1) "d" 59string(11) " 2147483648" 60string(11) "2147483648 " 61string(11) " 2147483648" 62string(11) " 632147483648" 64string(10) "2147483648" 65string(30) " 2147483648" 66string(4) "0-9]" 67string(1) "d" 68 69-- Iteration 2 -- 70string(11) "34359738369" 71string(1) "d" 72string(11) "34359738369" 73string(1) "d" 74string(12) " 34359738369" 75string(12) "34359738369 " 76string(12) " 34359738369" 77string(12) " 7834359738369" 79string(11) "34359738369" 80string(30) " 34359738369" 81string(4) "0-9]" 82string(1) "d" 83 84-- Iteration 3 -- 85string(10) "2147483649" 86string(1) "d" 87string(10) "2147483649" 88string(1) "d" 89string(11) " 2147483649" 90string(11) "2147483649 " 91string(11) " 2147483649" 92string(11) " 932147483649" 94string(10) "2147483649" 95string(30) " 2147483649" 96string(4) "0-9]" 97string(1) "d" 98 99-- Iteration 4 -- 100string(1) "0" 101string(1) "d" 102string(1) "0" 103string(1) "d" 104string(2) " 0" 105string(2) "0 " 106string(2) " 0" 107string(2) " 1080" 109string(4) " 0" 110string(30) " 0" 111string(4) "0-9]" 112string(1) "d" 113 114-- Iteration 5 -- 115string(1) "0" 116string(1) "d" 117string(1) "0" 118string(1) "d" 119string(2) " 0" 120string(2) "0 " 121string(2) " 0" 122string(2) " 1230" 124string(4) " 0" 125string(30) " 0" 126string(4) "0-9]" 127string(1) "d" 128 129-- Iteration 6 -- 130string(1) "1" 131string(1) "d" 132string(1) "1" 133string(1) "d" 134string(2) " 1" 135string(2) "1 " 136string(2) " 1" 137string(2) " 1381" 139string(4) " 1" 140string(30) " 1" 141string(4) "0-9]" 142string(1) "d" 143 144-- Iteration 7 -- 145string(6) "100000" 146string(1) "d" 147string(6) "100000" 148string(1) "d" 149string(7) " 100000" 150string(7) "100000 " 151string(7) " 100000" 152string(7) " 153100000" 154string(6) "100000" 155string(30) " 100000" 156string(4) "0-9]" 157string(1) "d" 158 159-- Iteration 8 -- 160string(8) "-1000000" 161string(1) "d" 162string(8) "-1000000" 163string(1) "d" 164string(9) " -1000000" 165string(9) "-1000000 " 166string(9) " -1000000" 167string(9) " 168-1000000" 169string(8) "-1000000" 170string(30) " -1000000" 171string(4) "0-9]" 172string(1) "d" 173 174-- Iteration 9 -- 175string(9) "100000000" 176string(1) "d" 177string(9) "100000000" 178string(1) "d" 179string(10) " 100000000" 180string(10) "100000000 " 181string(10) " 100000000" 182string(10) " 183100000000" 184string(9) "100000000" 185string(30) " 100000000" 186string(4) "0-9]" 187string(1) "d" 188 189-- Iteration 10 -- 190string(11) "-1000000000" 191string(1) "d" 192string(11) "-1000000000" 193string(1) "d" 194string(12) " -1000000000" 195string(12) "-1000000000 " 196string(12) " -1000000000" 197string(12) " 198-1000000000" 199string(11) "-1000000000" 200string(30) " -1000000000" 201string(4) "0-9]" 202string(1) "d" 203 204-- Iteration 11 -- 205string(2) "10" 206string(1) "d" 207string(2) "10" 208string(1) "d" 209string(3) " 10" 210string(3) "10 " 211string(3) " 10" 212string(3) " 21310" 214string(4) " 10" 215string(30) " 10" 216string(4) "0-9]" 217string(1) "d" 218 219-- Iteration 12 -- 220string(7) "1050000" 221string(1) "d" 222string(7) "1050000" 223string(1) "d" 224string(8) " 1050000" 225string(8) "1050000 " 226string(8) " 1050000" 227string(8) " 2281050000" 229string(7) "1050000" 230string(30) " 1050000" 231string(4) "0-9]" 232string(1) "d" 233Done 234