Changeset b524c5e0 in mainline
- Timestamp:
- 2006-01-04T11:43:23Z (19 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 5fe5f1e
- Parents:
- 0132630
- Files:
-
- 10 deleted
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
arch/amd64/Makefile.inc
r0132630 rb524c5e0 88 88 arch/$(ARCH)/src/mm/tlb.c \ 89 89 arch/$(ARCH)/src/asm_utils.S \ 90 arch/$(ARCH)/src/fmath.c \91 90 arch/$(ARCH)/src/mm/memory_init.c \ 92 91 arch/$(ARCH)/src/cpu/cpu.c \ -
arch/ia32/Makefile.inc
r0132630 rb524c5e0 116 116 arch/$(ARCH)/src/boot/boot.S \ 117 117 arch/$(ARCH)/src/boot/memmap.S \ 118 arch/$(ARCH)/src/fpu_context.c\ 119 arch/$(ARCH)/src/fmath.c 118 arch/$(ARCH)/src/fpu_context.c -
arch/ia64/Makefile.inc
r0132630 rb524c5e0 54 54 arch/$(ARCH)/src/ivt.S \ 55 55 arch/$(ARCH)/src/interrupt.c \ 56 arch/$(ARCH)/src/fmath.c \57 56 arch/$(ARCH)/src/mm/frame.c \ 58 57 arch/$(ARCH)/src/drivers/it.c -
arch/mips32/Makefile.inc
r0132630 rb524c5e0 109 109 arch/$(ARCH)/src/mm/vm.c \ 110 110 arch/$(ARCH)/src/fpu_context.c \ 111 arch/$(ARCH)/src/fmath.c \112 111 arch/$(ARCH)/src/drivers/arc.c \ 113 112 arch/$(ARCH)/src/drivers/msim.c \ -
arch/ppc32/Makefile.inc
r0132630 rb524c5e0 58 58 arch/$(ARCH)/src/mm/frame.c \ 59 59 arch/$(ARCH)/src/mm/memory_init.c \ 60 arch/$(ARCH)/src/mm/page.c \ 61 arch/$(ARCH)/src/fmath.c 60 arch/$(ARCH)/src/mm/page.c -
generic/src/debug/print.c
r0132630 rb524c5e0 32 32 #include <arch/arg.h> 33 33 #include <arch/asm.h> 34 #include <arch/fmath.h>35 34 36 35 #include <arch.h> … … 38 37 static char digits[] = "0123456789abcdef"; /**< Hexadecimal characters */ 39 38 SPINLOCK_INITIALIZE(printflock); /**< printf spinlock */ 40 41 #define DEFAULT_DOUBLE_PRECISION 1642 #define DEFAULT_DOUBLE_BUFFER_SIZE 12843 39 44 40 … … 106 102 107 103 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 divide153 * the number with a power of 10, print new number with better method for small numbers and154 * 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 209 104 210 105 /** General formatted text print … … 262 157 * must follow. 263 158 * 264 * e The next variant argument is treated as double precision float265 * and printed in exponent notation with only one digit before decimal point266 * 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 float271 * and printed in decimal notation in specified precision.272 *273 * F As with 'f'.274 *275 159 * All other characters from fmt except the formatting directives 276 160 * are printed in verbatim. … … 284 168 char c; 285 169 286 __u16 precision;287 288 170 va_start(ap, fmt); 289 171 … … 296 178 /* control character */ 297 179 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 }307 180 308 181 switch (c = fmt[i++]) { … … 355 228 print_fixed_hex(va_arg(ap, __native), INT8); 356 229 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 376 231 /* 377 232 * Decimal and hexadecimal conversions. -
test/print/print1/test.c
r0132630 rb524c5e0 32 32 { 33 33 __u64 u64const = 0x0123456789ABCDEFLL; 34 double d;35 34 printf(" Printf test \n"); 36 35 printf(" Q %Q %q \n",u64const, u64const); … … 38 37 printf(" W %W %w \n",0x0123 ,0x0123); 39 38 printf(" B %B %b \n",0x01 ,0x01); 40 printf(" F %F %f (123456789.987654321)\n",123456789.987654321,123456789.987654321);41 printf(" F %F %f (-123456789.987654321e-10)\n",-123456789.987654321e-10,-123456789.987654321e-10);42 printf(" E %E %e (123456789.987654321)\n",123456789.987654321,123456789.987654321);43 printf(" E %.10E %.8e (-123456789.987654321e-12 for precision 10 & 8)\n",-123456789.987654321e-12,-123456789.987654321e-12);44 printf(" E %.10E %.8e (-987654321.123456789e-12 for precision 10 & 8)\n",-987654321.123456789e-12,-987654321.123456789e-12);45 printf(" E %.10E %.8e (123456789.987654321e-12 for precision 10 & 8)\n",123456789.987654321e-12,123456789.987654321e-12);46 printf(" E %.10E %.8e (987654321.123456789e-12 for precision 10 & 8)\n",987654321.123456789e-12,987654321.123456789e-12);47 printf(" E %.10E %.8e (-123456789.987654321e12 for precision 10 & 8)\n",-123456789.987654321e12,-123456789.987654321e12);48 printf(" E %.10E %.8e (-987654321.123456789e12 for precision 10 & 8)\n",-987654321.123456789e12,-987654321.123456789e12);49 printf(" E %.10E %.8e (123456789.987654321e12 for precision 10 & 8)\n",123456789.987654321e12,123456789.987654321e12);50 printf(" E %.10E %.8e (987654321.123456789e12 for precision 10 & 8)\n",987654321.123456789e12,987654321.123456789e12);51 u64const =0x7fffffffffffffffLL;52 d =*((double *)((void *)(&u64const)));53 printf(" E %.10E (NaN)\n",d);54 u64const =(0xfff0000000000000LL);55 d =*(double *)(void *)(&u64const);56 printf(" E %.10E (-Inf)\n",d);57 39 return; 58 40 }
Note:
See TracChangeset
for help on using the changeset viewer.