Subversion Repositories HelenOS-historic

Compare Revisions

Ignore whitespace Rev 227 → Rev 228

/SPARTAN/trunk/test/print/print1/test.c
36,5 → 36,7
printf(" L %L %l \n",0x01234567 ,0x01234567);
printf(" W %W %w \n",0x0123 ,0x0123);
printf(" B %B %b \n",0x01 ,0x01);
printf(" F %F %f (123456789.987654321)\n",123456789.987654321,123456789.987654321);
printf(" F %F %f (-123456789.987654321e-10)\n",-123456789.987654321e-10,-123456789.987654321e-10);
return;
}
/SPARTAN/trunk/include/print.h
36,6 → 36,7
#define INT32 4
#define INT64 8
 
static void print_double(double num,__u16 precision) ;
static void print_str(const char *str);
static void print_fixed_hex(const __u64 num, const int width);
static void print_number(const __native num, const unsigned int base);
/SPARTAN/trunk/src/debug/print.c
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':
/SPARTAN/trunk/arch/ia32/Makefile.inc
47,4 → 47,5
arch/drivers/ega.c \
arch/boot/boot.S \
arch/boot/memmap.S\
arch/fpu_context.c
arch/fpu_context.c\
arch/fmath.c