Changeset b524c5e0 in mainline for generic/src/debug/print.c


Ignore:
Timestamp:
2006-01-04T11:43:23Z (19 years ago)
Author:
Josef Cejka <malyzelenyhnus@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
5fe5f1e
Parents:
0132630
Message:

Support for printing float numbers in kernel removed.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • generic/src/debug/print.c

    r0132630 rb524c5e0  
    3232#include <arch/arg.h>
    3333#include <arch/asm.h>
    34 #include <arch/fmath.h>
    3534
    3635#include <arch.h>
     
    3837static char digits[] = "0123456789abcdef";      /**< Hexadecimal characters */
    3938SPINLOCK_INITIALIZE(printflock);                /**< printf spinlock */
    40 
    41 #define DEFAULT_DOUBLE_PRECISION 16
    42 #define DEFAULT_DOUBLE_BUFFER_SIZE 128
    4339
    4440
     
    106102
    107103
    108 static void print_double(double num, __u8 modifier, __u16 precision)
    109 {
    110         double intval,intval2;
    111         int counter;
    112         int exponent,exponenttmp;
    113         unsigned char buf[DEFAULT_DOUBLE_BUFFER_SIZE];
    114         unsigned long in1,in2; 
    115        
    116 
    117         if (fmath_is_nan(num)) {
    118                 print_str("NaN");
    119                 return;
    120         }
    121        
    122         if (num<0.0) {
    123                 putchar('-');
    124                 num=num*-1.0;
    125         }
    126 
    127 
    128         if (fmath_is_infinity(num)) {
    129                 print_str("Inf");
    130                 return;
    131         }
    132 
    133         if ((modifier=='E')||(modifier=='e')) {
    134                 intval2=fmath_fint(fmath_get_decimal_exponent(num),&intval);
    135                 exponent=intval;
    136                 if ((intval2<0.0)) exponent--;
    137                 num = num / ((fmath_dpow(10.0,exponent)));
    138                
    139                 print_double(num,modifier+1,precision); /* modifier+1 = E => F or e => f */
    140                 putchar(modifier);
    141                 if (exponent<0) {
    142                         putchar('-');
    143                         exponent*=-1;
    144                 }
    145                 print_number(exponent,10);
    146                 return;
    147         }
    148                
    149         /* TODO: rounding constant - when we got fraction >= 0.5, we must increment last printed number */
    150 
    151         /*
    152          * Here is a problem with cumulative error while printing big double values -> we will divide
    153          * the number with a power of 10, print new number with better method for small numbers and
    154          * then print decimal point at correct position.
    155          */
    156        
    157         fmath_fint(fmath_get_decimal_exponent(num),&intval);
    158        
    159         exponent=(intval>0.0?intval:0);
    160        
    161         precision+=exponent;
    162        
    163         if (exponent>0) num = num / ((fmath_dpow(10.0,exponent)));
    164                
    165         num=fmath_fint(num,&intval);
    166        
    167         if (precision>0) {
    168                 counter=precision-1;
    169                 if (exponent>0) counter++;
    170                
    171                 if (counter>=DEFAULT_DOUBLE_BUFFER_SIZE) {
    172                         counter=DEFAULT_DOUBLE_BUFFER_SIZE;
    173                 }
    174                 exponenttmp=exponent;
    175                 while(counter>=0) {
    176                         num *= 10.0;
    177                         num = fmath_fint(num,&intval2);
    178                         buf[counter--]=((int)intval2)+'0';
    179                         exponenttmp--;
    180                         if ((exponenttmp==0)&&(counter>=0)) buf[counter--]='.';
    181                 }
    182                 counter=precision;
    183                 if ((exponent==0)&&(counter<DEFAULT_DOUBLE_BUFFER_SIZE)) buf[counter]='.';
    184                 counter++;     
    185         } else {
    186                 counter=0;     
    187         }
    188        
    189         in1=intval;
    190         if (in1==0.0) {
    191                 if (counter<DEFAULT_DOUBLE_BUFFER_SIZE) buf[counter++]='0';
    192         } else {
    193                 while(( in1>0 )&&(counter<DEFAULT_DOUBLE_BUFFER_SIZE)) {
    194                        
    195                         in2=in1;
    196                         in1/=10;
    197                         buf[counter]=in2-in1*10 + '0';
    198                         counter++;
    199                 }
    200         }
    201        
    202         counter = (counter>=DEFAULT_DOUBLE_BUFFER_SIZE?DEFAULT_DOUBLE_BUFFER_SIZE:counter);
    203         while (counter>0) {
    204                 putchar(buf[--counter]);
    205         }
    206         return;
    207 }
    208 
    209104
    210105/** General formatted text print
     
    262157 *      must follow.
    263158 *
    264  * e    The next variant argument is treated as double precision float
    265  *      and printed in exponent notation with only one digit before decimal point
    266  *      in specified precision. The exponent sign is printed as 'e'.
    267  *
    268  * E    As with 'e', but the exponent sign is printed as 'E'.
    269  *
    270  * f    The next variant argument is treated as double precision float
    271  *      and printed in decimal notation in specified precision.
    272  *
    273  * F    As with 'f'.
    274  *
    275159 * All other characters from fmt except the formatting directives
    276160 * are printed in verbatim.
     
    284168        char c;
    285169       
    286         __u16 precision;
    287        
    288170        va_start(ap, fmt);
    289171
     
    296178                    /* control character */
    297179                    case '%':
    298                         precision = DEFAULT_DOUBLE_PRECISION;
    299                         if (fmt[i]=='.') {
    300                                 precision=0;
    301                                 c=fmt[++i];
    302                                 while((c>='0')&&(c<='9')) {
    303                                         precision = precision*10 + c - '0';
    304                                         c=fmt[++i];
    305                                 }
    306                         }
    307180                   
    308181                        switch (c = fmt[i++]) {
     
    355228                                print_fixed_hex(va_arg(ap, __native), INT8);
    356229                                goto loop;
    357 
    358                             /*
    359                              * Floating point conversions.
    360                              */
    361                             case 'F':
    362                                 print_double(va_arg(ap, double),'F',precision);
    363                                 goto loop;
    364                                        
    365                             case 'f':
    366                                 print_double(va_arg(ap, double),'f',precision);
    367                                 goto loop;
    368                                
    369                             case 'E':
    370                                 print_double(va_arg(ap, double),'E',precision);
    371                                 goto loop;
    372                             case 'e':
    373                                 print_double(va_arg(ap, double),'e',precision);
    374                                 goto loop;
    375                                
     230       
    376231                            /*
    377232                             * Decimal and hexadecimal conversions.
Note: See TracChangeset for help on using the changeset viewer.