hiphop-php /hphp/test/zend/bad/ext/standard/tests/strings/printf_64bit.php

Language PHP Lines 216
MD5 Hash b542b2aa651da375454732eb011b7464 Estimated Cost $3,428 (why?)
Repository git://github.com/facebook/hiphop-php.git View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<?php

/* Various input arrays for different format types */

$float_variation  = array( "%f", "%-f", "%+f", "%7.2f", "%-7.2f", "%07.2f", "%-07.2f", "%'#7.2f" );
$float_numbers    = array( 0, 1, -1, 0.32, -0.32, 3.4. -3.4, 2.54, -2.54, 1.2345678e99, -1.2345678e99 );

$int_variation    = array( "%d", "%-d", "%+d", "%7.2d", "%-7.2d", "%07.2d", "%-07.2d", "%'#7.2d" );
$int_numbers      = array( 0, 1, -1, 2.7, -2.7, 23333333, -23333333, "1234" );

$char_variation   = array( 'a', "a", 67, -67, 99 );

$string_variation = array( "%5s", "%-5s", "%05s", "%'#5s" );
$strings          = array( NULL, "abc", 'aaa' );

/* Checking warning messages */

/* Zero argument */
echo "\n*** Output for zero argument ***\n";
printf();

/* Number of arguments not matching as specified in format field */
echo "\n*** Output for insufficient number of arguments ***\n";
$string = "dingy%sflem%dwombat";
$nbr = 5;
$name = "voudras";
printf("%d $string %s", $nbr, $name);


/* Scalar argument */
echo "\n*** Output for scalar argument ***\n";
printf(3);

/* NULL argument */
echo "\n*** Output for NULL as argument ***\n";
printf(NULL);


/* Float type variations */

$counter = 1;
echo "\n\n*** Output for float type ***\n";
echo "\n Input Float numbers variation array is:\n";
print_r($float_numbers);

foreach( $float_variation as $float_var )
{
 echo "\n\nFloat Iteration $counter";
 foreach( $float_numbers as $float_num )
 {
  echo "\n";
  printf( $float_var, $float_num );
 }
 $counter++;
}


/* Integer type variations */

$counter = 1;
echo "\n\n*** Output for integer type ***\n";
echo "\n Input Integer numbers variation array is:\n";
print_r($int_numbers);

foreach( $int_variation as $int_var )
{
 echo "\n\nInteger Iteration $counter";
 foreach( $int_numbers as $int_num )
 {
  echo "\n";
  printf( $int_var, $int_num );
 }
 $counter++;
}


/* Binary type variations */

echo "\n\n*** Output for binary type ***\n";
echo "\n Input  numbers variation array is:\n";
print_r($int_numbers);

 foreach( $int_numbers as $bin_num )
 {
  echo "\n";
  printf( "%b", $bin_num );
 }


/* Chararter type variations */
echo "\n\n*** Output for char type ***\n";
echo "\n Input Characters variation array is:\n";
print_r($char_variation);

foreach( $char_variation as $char )
{
 echo "\n";
 printf( "%c", $char );
}

/* Scientific type variations */
echo "\n\n*** Output for scientific type ***\n";
echo "\n Input numbers variation array is:\n";
print_r($int_numbers);

foreach( $int_numbers as $num )
{
 echo "\n";
 printf( "%e", $num );
}

/* Unsigned Integer type variation */
echo "\n\n*** Output for unsigned integer type ***\n";
echo "\n Input Integer numbers variation array is:\n";
print_r($int_numbers);

foreach( $int_numbers as $unsig_num )
{
 echo "\n";
 printf( "%u", $unsig_num );
}

/* Octal type variations */
echo "\n\n*** Output for octal type ***\n";
echo "\n Input numbers variation array is:\n";
print_r($int_numbers);

foreach( $int_numbers as $octal_num )
{
 echo "\n";
 printf( "%o", $octal_num );
}

/* Hexadecimal type variations */
echo "\n\n*** Output for hexadecimal type ***\n";
echo "\n Input numbers variation array is:\n";
print_r($int_numbers);

foreach( $int_numbers as $hexa_num )
{
 echo "\n";
 printf( "%x", $hexa_num );
}

/* String type variations */
echo "\n\n*** Output for string type ***\n";
echo "\n Input Strings format variation array is:\n";
print_r($string_variation);
echo "\n Input strings variation array is:\n";
print_r($strings);

foreach( $string_variation as $string_var )
{
 foreach( $strings as $str )
 {
  echo "\n";
  printf( $string_var, $str );
 }
}


/* variations of %g type */
$format_g = array("%g", "%.0g", "%+g", "%-g", "%-1.2g", "%+1.2g", "%G", "%.0G", "%+G", "%-G", "%-1.2G", "%+1.2G");

echo "\n\n*** Output for '%g' type ***\n";
echo "\n Input format variation array is:\n";
print_r($format_g);

foreach( $format_g as $formatg )
{
 printf("\n$formatg",123456);
 printf("\n$formatg",-123456);
}


/* Some more typical cases */

$tempnum = 12345;
$tempstring = "abcdefghjklmnpqrstuvwxyz";

echo"\n\n*** Output for '%%%.2f' as the format parameter ***\n";
printf("%%%.2f",1.23456789e10);

echo"\n\n*** Output for '%%' as the format parameter ***\n";
printf("%%",1.23456789e10);

echo"\n\n*** Output for precision value more than maximum ***\n";
printf("%.988f",1.23456789e10);   

echo"\n\n*** Output for invalid width(-15) specifier ***\n";
printf("%030.-15s", $tempstring);  

echo"\n\n*** Output for '%F' as the format parameter ***\n";
printf("%F",1.23456789e10);

echo"\n\n*** Output for '%X' as the format parameter ***\n";
printf("%X",12);

echo"\n\n*** Output  with no format parameter ***\n";
printf($tempnum);

echo"\n\n*** Output for multiple format parameters ***\n";
printf("%d  %s  %d\n", $tempnum, $tempstring, $tempnum); 

echo"\n\n*** Output for excess of mixed type arguments  ***\n";
printf("%s", $tempstring, $tempstring, $tempstring);      

echo"\n\n*** Output for string format parameter and integer type argument ***\n";
printf("%s", $tempnum);          

echo"\n\n*** Output for integer format parameter and string type argument ***\n";
printf("%d", $tempstring);    


?>
Back to Top