Rev 276 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 276 | Rev 323 | ||
---|---|---|---|
Line 56... | Line 56... | ||
56 | } |
56 | } |
57 | 57 | ||
58 | if (num<0.0) { |
58 | if (num<0.0) { |
59 | putchar('-'); |
59 | putchar('-'); |
60 | num=num*-1.0; |
60 | num=num*-1.0; |
61 | } |
61 | } |
62 | 62 | ||
63 | 63 | ||
64 | if (fmath_is_infinity(num)) { |
64 | if (fmath_is_infinity(num)) { |
65 | print_str("Inf"); |
65 | print_str("Inf"); |
66 | return; |
66 | return; |
67 | } |
67 | } |
68 | 68 | ||
69 | if ((modifier=='E')||(modifier=='e')) { |
69 | if ((modifier=='E')||(modifier=='e')) { |
70 | intval2=fmath_fint(fmath_get_decimal_exponent(num),&intval); |
70 | intval2=fmath_fint(fmath_get_decimal_exponent(num),&intval); |
71 | exponent=intval; |
71 | exponent=intval; |
72 | if ((intval2<0.0)) exponent--; |
72 | if ((intval2<0.0)) exponent--; |
73 | num = num / ((fmath_dpow(10.0,exponent))); |
73 | num = num / ((fmath_dpow(10.0,exponent))); |
74 | 74 | ||
75 | print_double(num,modifier+1,precision); //modifier+1 = E => F or e => f |
75 | print_double(num,modifier+1,precision); /* modifier+1 = E => F or e => f */ |
76 | putchar(modifier); |
76 | putchar(modifier); |
77 | if (exponent<0) { |
77 | if (exponent<0) { |
78 | putchar('-'); |
78 | putchar('-'); |
79 | exponent*=-1; |
79 | exponent*=-1; |
80 | } |
80 | } |
81 | print_number(exponent,10); |
81 | print_number(exponent,10); |
82 | return; |
82 | return; |
83 | } |
83 | } |
84 | 84 | ||
85 | //TODO: rounding constant - when we got fraction >= 0.5, we must increment last printed number |
85 | /* TODO: rounding constant - when we got fraction >= 0.5, we must increment last printed number */ |
86 | 86 | ||
- | 87 | /* |
|
87 | /* Here is problem with cumulative error while printing big double values -> we will divide |
88 | * Here is a problem with cumulative error while printing big double values -> we will divide |
88 | the number with a power of 10, print new number with better method for small numbers and then print decimal point at correct position */ |
89 | * the number with a power of 10, print new number with better method for small numbers and |
- | 90 | * then print decimal point at correct position. |
|
- | 91 | */ |
|
89 | 92 | ||
90 | fmath_fint(fmath_get_decimal_exponent(num),&intval); |
93 | fmath_fint(fmath_get_decimal_exponent(num),&intval); |
91 | 94 | ||
92 | exponent=(intval>0.0?intval:0); |
95 | exponent=(intval>0.0?intval:0); |
93 | 96 | ||
Line 133... | Line 136... | ||
133 | } |
136 | } |
134 | 137 | ||
135 | counter = (counter>=DEFAULT_DOUBLE_BUFFER_SIZE?DEFAULT_DOUBLE_BUFFER_SIZE:counter); |
138 | counter = (counter>=DEFAULT_DOUBLE_BUFFER_SIZE?DEFAULT_DOUBLE_BUFFER_SIZE:counter); |
136 | while (counter>0) { |
139 | while (counter>0) { |
137 | putchar(buf[--counter]); |
140 | putchar(buf[--counter]); |
138 | }; |
141 | } |
139 | return; |
142 | return; |
140 | } |
143 | } |
141 | 144 | ||
142 | /** Print NULL terminated string |
145 | /** Print NULL terminated string |
143 | * |
146 | * |
Line 234... | Line 237... | ||
234 | * digits). |
237 | * digits). |
235 | * x The next variant argument is treated as integer |
238 | * x The next variant argument is treated as integer |
236 | * and printed in standard hexadecimal format (only significant |
239 | * and printed in standard hexadecimal format (only significant |
237 | * digits). |
240 | * digits). |
238 | * X As with 'x', but '0x' is prefixed. |
241 | * X As with 'x', but '0x' is prefixed. |
- | 242 | * . The decimal number following period will be treated as precision |
|
- | 243 | * for printing floating point numbers. One of 'e', 'E', 'f' or 'F' |
|
- | 244 | * must follow. |
|
- | 245 | * e The next variant argument is treated as double precision float |
|
- | 246 | * and printed in exponent notation with only one digit before decimal point |
|
- | 247 | * in specified precision. The exponent sign is printed as 'e'. |
|
- | 248 | * E As with 'e', but the exponent sign is printed as 'E'. |
|
- | 249 | * f The next variant argument is treated as double precision float |
|
- | 250 | * and printed in decimal notation in specified precision. |
|
- | 251 | * F As with 'f'. |
|
239 | * |
252 | * |
240 | * All other characters from fmt except the formatting directives |
253 | * All other characters from fmt except the formatting directives |
241 | * are printed in verbatim. |
254 | * are printed in verbatim. |
242 | * |
255 | * |
243 | * @param fmt Formatting NULL terminated string. |
256 | * @param fmt Formatting NULL terminated string. |
Line 257... | Line 270... | ||
257 | spinlock_lock(&printflock); |
270 | spinlock_lock(&printflock); |
258 | 271 | ||
259 | while (c = fmt[i++]) { |
272 | while (c = fmt[i++]) { |
260 | switch (c) { |
273 | switch (c) { |
261 | 274 | ||
262 | - | ||
263 | - | ||
264 | /* control character */ |
275 | /* control character */ |
265 | case '%': |
276 | case '%': |
266 | - | ||
267 | precision = DEFAULT_DOUBLE_PRECISION; |
277 | precision = DEFAULT_DOUBLE_PRECISION; |
268 | if (fmt[i]=='.') { |
278 | if (fmt[i]=='.') { |
269 | precision=0; |
279 | precision=0; |
- | 280 | c=fmt[++i]; |
|
- | 281 | while((c>='0')&&(c<='9')) { |
|
- | 282 | precision = precision*10 + c - '0'; |
|
270 | c=fmt[++i]; |
283 | c=fmt[++i]; |
271 | while((c>='0')&&(c<='9')) { |
- | |
272 | precision = precision*10 + c - '0'; |
- | |
273 | c=fmt[++i]; |
- | |
274 | } |
- | |
275 | - | ||
276 | } |
284 | } |
- | 285 | } |
|
277 | 286 | ||
278 | switch (c = fmt[i++]) { |
287 | switch (c = fmt[i++]) { |
279 | 288 | ||
280 | /* percentile itself */ |
289 | /* percentile itself */ |
281 | case '%': |
290 | case '%': |
282 | break; |
291 | break; |
283 | 292 | ||
284 | /* |
293 | /* |
285 | * String and character conversions. |
294 | * String and character conversions. |
286 | */ |
295 | */ |
287 | case 's': |
296 | case 's': |
288 | print_str(va_arg(ap, char_ptr)); |
297 | print_str(va_arg(ap, char_ptr)); |
289 | goto loop; |
298 | goto loop; |
290 | 299 | ||
291 | case 'c': |
300 | case 'c': |
292 | c = (char) va_arg(ap, int); |
301 | c = (char) va_arg(ap, int); |
293 | break; |
302 | break; |
294 | 303 | ||
295 | /* |
304 | /* |
296 | * Hexadecimal conversions with fixed width. |
305 | * Hexadecimal conversions with fixed width. |
297 | */ |
306 | */ |
298 | case 'P': |
307 | case 'P': |
299 | print_str("0x"); |
308 | print_str("0x"); |
300 | case 'p': |
309 | case 'p': |
301 | print_fixed_hex(va_arg(ap, __native), sizeof(__native)); |
310 | print_fixed_hex(va_arg(ap, __native), sizeof(__native)); |
302 | goto loop; |
311 | goto loop; |
303 | 312 | ||
304 | case 'Q': |
313 | case 'Q': |
305 | print_str("0x"); |
314 | print_str("0x"); |
306 | case 'q': |
315 | case 'q': |
307 | print_fixed_hex(va_arg(ap, __u64), INT64); |
316 | print_fixed_hex(va_arg(ap, __u64), INT64); |
308 | goto loop; |
317 | goto loop; |
309 | 318 | ||
310 | case 'L': |
319 | case 'L': |
311 | print_str("0x"); |
320 | print_str("0x"); |
312 | case 'l': |
321 | case 'l': |
313 | print_fixed_hex(va_arg(ap, __native), INT32); |
322 | print_fixed_hex(va_arg(ap, __native), INT32); |
314 | goto loop; |
323 | goto loop; |
315 | 324 | ||
316 | case 'W': |
325 | case 'W': |
317 | print_str("0x"); |
326 | print_str("0x"); |
318 | case 'w': |
327 | case 'w': |
319 | print_fixed_hex(va_arg(ap, __native), INT16); |
328 | print_fixed_hex(va_arg(ap, __native), INT16); |
320 | goto loop; |
329 | goto loop; |
321 | 330 | ||
322 | case 'B': |
331 | case 'B': |
323 | print_str("0x"); |
332 | print_str("0x"); |
324 | case 'b': |
333 | case 'b': |
325 | print_fixed_hex(va_arg(ap, __native), INT8); |
334 | print_fixed_hex(va_arg(ap, __native), INT8); |
326 | goto loop; |
335 | goto loop; |
327 | 336 | ||
328 | /* |
337 | /* |
329 | * Floating point conversions. |
338 | * Floating point conversions. |
330 | */ |
339 | */ |
331 | - | ||
332 | case 'F': |
340 | case 'F': |
333 | print_double(va_arg(ap, double),'F',precision); |
341 | print_double(va_arg(ap, double),'F',precision); |
334 | goto loop; |
342 | goto loop; |
335 | 343 | ||
336 | case 'f': |
344 | case 'f': |
337 | print_double(va_arg(ap, double),'f',precision); |
345 | print_double(va_arg(ap, double),'f',precision); |
338 | goto loop; |
346 | goto loop; |
339 | 347 | ||
340 | case 'E': |
348 | case 'E': |
341 | print_double(va_arg(ap, double),'E',precision); |
349 | print_double(va_arg(ap, double),'E',precision); |
342 | goto loop; |
350 | goto loop; |
343 | case 'e': |
351 | case 'e': |
344 | print_double(va_arg(ap, double),'e',precision); |
352 | print_double(va_arg(ap, double),'e',precision); |
345 | goto loop; |
353 | goto loop; |
346 | 354 | ||
347 | /* |
355 | /* |
348 | * Decimal and hexadecimal conversions. |
356 | * Decimal and hexadecimal conversions. |
349 | */ |
357 | */ |
350 | case 'd': |
358 | case 'd': |
351 | print_number(va_arg(ap, __native), 10); |
359 | print_number(va_arg(ap, __native), 10); |
352 | goto loop; |
360 | goto loop; |
353 | 361 | ||
354 | case 'X': |
362 | case 'X': |
355 | print_str("0x"); |
363 | print_str("0x"); |
356 | case 'x': |
364 | case 'x': |
357 | print_number(va_arg(ap, __native), 16); |
365 | print_number(va_arg(ap, __native), 16); |
358 | goto loop; |
366 | goto loop; |
359 | 367 | ||
360 | /* |
368 | /* |
361 | * Bad formatting. |
369 | * Bad formatting. |
362 | */ |
370 | */ |
363 | default: |
371 | default: |
364 | goto out; |
372 | goto out; |
365 | } |
373 | } |
366 | 374 | ||
367 | default: putchar(c); |
375 | default: putchar(c); |
368 | } |
376 | } |
369 | 377 | ||
370 | loop: |
378 | loop: |