Rev 228 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 228 | Rev 264 | ||
---|---|---|---|
Line 39... | Line 39... | ||
39 | static spinlock_t printflock; /**< printf spinlock */ |
39 | static spinlock_t printflock; /**< printf spinlock */ |
40 | 40 | ||
41 | #define DEFAULT_DOUBLE_PRECISION 16 |
41 | #define DEFAULT_DOUBLE_PRECISION 16 |
42 | #define DEFAULT_DOUBLE_BUFFER_SIZE 128 |
42 | #define DEFAULT_DOUBLE_BUFFER_SIZE 128 |
43 | 43 | ||
44 | void print_double(double num, __u16 precision) |
44 | void print_double(double num, __u8 modifier, __u16 precision) |
45 | { |
45 | { |
46 | double intval,intval2; |
46 | double intval,intval2; |
47 | int counter; |
47 | int counter; |
48 | int exponent,exponenttmp; |
48 | int exponent,exponenttmp; |
49 | unsigned char buf[DEFAULT_DOUBLE_BUFFER_SIZE]; |
49 | unsigned char buf[DEFAULT_DOUBLE_BUFFER_SIZE]; |
50 | unsigned long in1,in2; |
50 | unsigned long in1,in2; |
- | 51 | ||
51 | /* |
52 | /* |
52 | if (fmath_is_nan(num)) { |
53 | if (fmath_is_nan(num)) { |
53 | print_str("NaN"); |
54 | print_str("NaN"); |
54 | return; |
55 | return; |
55 | } |
56 | } |
Line 59... | Line 60... | ||
59 | putchar('-'); |
60 | putchar('-'); |
60 | } |
61 | } |
61 | 62 | ||
62 | num=fmath_abs(num); |
63 | num=fmath_abs(num); |
63 | 64 | ||
- | 65 | if ((modifier=='E')||(modifier=='e')) { |
|
- | 66 | intval2=fmath_fint(fmath_get_decimal_exponent(num),&intval); |
|
- | 67 | exponent=intval; |
|
- | 68 | if ((intval2<0.0)&&(exponent<0)) exponent--; |
|
- | 69 | num = num / ((fmath_dpow(10.0,exponent))); |
|
- | 70 | ||
- | 71 | print_double(num,modifier+1,precision); //modifier+1 = E => F or e => f |
|
- | 72 | putchar(modifier); |
|
- | 73 | if (exponent<0) { |
|
- | 74 | putchar('-'); |
|
- | 75 | exponent*=-1; |
|
- | 76 | } |
|
- | 77 | print_number(exponent,10); |
|
- | 78 | return; |
|
- | 79 | } |
|
- | 80 | ||
- | 81 | ||
64 | /* |
82 | /* |
65 | if (fmath_is_infinity(num)) { |
83 | if (fmath_is_infinity(num)) { |
66 | print_str("Inf"); |
84 | print_str("Inf"); |
67 | } |
85 | } |
68 | */ |
86 | */ |
Line 230... | Line 248... | ||
230 | void printf(const char *fmt, ...) |
248 | void printf(const char *fmt, ...) |
231 | { |
249 | { |
232 | int irqpri, i = 0; |
250 | int irqpri, i = 0; |
233 | va_list ap; |
251 | va_list ap; |
234 | char c; |
252 | char c; |
- | 253 | ||
- | 254 | __u16 precision; |
|
235 | 255 | ||
236 | va_start(ap, fmt); |
256 | va_start(ap, fmt); |
237 | 257 | ||
238 | irqpri = cpu_priority_high(); |
258 | irqpri = cpu_priority_high(); |
239 | spinlock_lock(&printflock); |
259 | spinlock_lock(&printflock); |
240 | 260 | ||
241 | while (c = fmt[i++]) { |
261 | while (c = fmt[i++]) { |
242 | switch (c) { |
262 | switch (c) { |
243 | 263 | ||
- | 264 | ||
- | 265 | ||
244 | /* control character */ |
266 | /* control character */ |
245 | case '%': |
267 | case '%': |
- | 268 | ||
- | 269 | precision = DEFAULT_DOUBLE_PRECISION; |
|
- | 270 | if (fmt[i]=='.') { |
|
- | 271 | precision=0; |
|
- | 272 | c=fmt[++i]; |
|
- | 273 | while((c>='0')&&(c<='9')) { |
|
- | 274 | precision = precision*10 + c - '0'; |
|
- | 275 | c=fmt[++i]; |
|
- | 276 | } |
|
- | 277 | ||
- | 278 | } |
|
- | 279 | ||
246 | switch (c = fmt[i++]) { |
280 | switch (c = fmt[i++]) { |
247 | 281 | ||
248 | /* percentile itself */ |
282 | /* percentile itself */ |
249 | case '%': |
283 | case '%': |
250 | break; |
284 | break; |
Line 296... | Line 330... | ||
296 | /* |
330 | /* |
297 | * Floating point conversions. |
331 | * Floating point conversions. |
298 | */ |
332 | */ |
299 | 333 | ||
300 | case 'F': |
334 | case 'F': |
- | 335 | print_double(va_arg(ap, double),'F',precision); |
|
- | 336 | goto loop; |
|
- | 337 | ||
301 | case 'f': |
338 | case 'f': |
302 | print_double(va_arg(ap, double),DEFAULT_DOUBLE_PRECISION); |
339 | print_double(va_arg(ap, double),'f',precision); |
303 | goto loop; |
340 | goto loop; |
- | 341 | ||
- | 342 | case 'E': |
|
- | 343 | print_double(va_arg(ap, double),'E',precision); |
|
- | 344 | goto loop; |
|
- | 345 | case 'e': |
|
- | 346 | print_double(va_arg(ap, double),'e',precision); |
|
- | 347 | goto loop; |
|
- | 348 | ||
304 | /* |
349 | /* |
305 | * Decimal and hexadecimal conversions. |
350 | * Decimal and hexadecimal conversions. |
306 | */ |
351 | */ |
307 | case 'd': |
352 | case 'd': |
308 | print_number(va_arg(ap, __native), 10); |
353 | print_number(va_arg(ap, __native), 10); |