31,13 → 31,98 |
#include <synch/spinlock.h> |
#include <arch/arg.h> |
#include <arch/asm.h> |
#include <arch/fmath.h> |
|
#include <arch.h> |
|
|
static char digits[] = "0123456789abcdef"; /**< Hexadecimal characters */ |
static spinlock_t printflock; /**< printf spinlock */ |
|
#define DEFAULT_DOUBLE_PRECISION 16 |
#define DEFAULT_DOUBLE_BUFFER_SIZE 128 |
|
void print_double(double num, __u16 precision) |
{ |
double intval,intval2; |
int counter; |
int exponent,exponenttmp; |
unsigned char buf[DEFAULT_DOUBLE_BUFFER_SIZE]; |
unsigned long in1,in2; |
/* |
if (fmath_is_nan(num)) { |
print_str("NaN"); |
return; |
} |
*/ |
|
if (fmath_is_negative(num)) { |
putchar('-'); |
} |
|
num=fmath_abs(num); |
|
/* |
if (fmath_is_infinity(num)) { |
print_str("Inf"); |
} |
*/ |
//TODO: rounding constant - when we got fraction >= 0.5, we must increment last printed number |
|
/* Here is problem with cumulative error while printing big double values -> we will divide |
the number with a power of 10, print new number with better method for small numbers and then print decimal point at correct position */ |
|
fmath_fint(fmath_get_decimal_exponent(num),&intval); |
|
exponent=(intval>0.0?intval:0); |
|
precision+=exponent; |
|
if (exponent>0) num = num / ((fmath_dpow(10.0,exponent))); |
|
num=fmath_fint(num,&intval); |
|
if (precision>0) { |
counter=precision-1; |
if (exponent>0) counter++; |
|
if (counter>=DEFAULT_DOUBLE_BUFFER_SIZE) { |
counter=DEFAULT_DOUBLE_BUFFER_SIZE; |
} |
exponenttmp=exponent; |
while(counter>=0) { |
num *= 10.0; |
num = fmath_fint(num,&intval2); |
buf[counter--]=((int)intval2)+'0'; |
exponenttmp--; |
if ((exponenttmp==0)&&(counter>=0)) buf[counter--]='.'; |
} |
counter=precision; |
if ((exponent==0)&&(counter<DEFAULT_DOUBLE_BUFFER_SIZE)) buf[counter]='.'; |
counter++; |
} else { |
counter=0; |
} |
|
if (intval==0.0) { |
if (counter<DEFAULT_DOUBLE_BUFFER_SIZE) buf[counter++]='0'; |
} else { |
in1=intval; |
while(( in1>0 )&&(counter<DEFAULT_DOUBLE_BUFFER_SIZE)) { |
|
in2=in1; |
in1/=10; |
buf[counter]=in2-in1*10 + '0'; |
counter++; |
} |
} |
|
counter = (counter>=DEFAULT_DOUBLE_BUFFER_SIZE?DEFAULT_DOUBLE_BUFFER_SIZE:counter); |
while (counter>0) { |
putchar(buf[--counter]); |
}; |
return; |
} |
|
/** Print NULL terminated string |
* |
* Print characters from str using putchar() until |
209,6 → 294,14 |
goto loop; |
|
/* |
* Floating point conversions. |
*/ |
|
case 'F': |
case 'f': |
print_double(va_arg(ap, double),DEFAULT_DOUBLE_PRECISION); |
goto loop; |
/* |
* Decimal and hexadecimal conversions. |
*/ |
case 'd': |