- Timestamp:
- Mar 22, 2016, 5:40:12 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/giet_libs/stdlib.c
r801 r810 230 230 break; 231 231 } 232 case (' e'):233 case ('f'):234 case ('g'): // IEEE754 64 bits232 case ('f'): // IEEE754 64 bits 233 // integer part : up to 10 decimal digits 234 // decimal part : 9 decimal digits 235 235 { 236 236 union … … 242 242 val.d = va_arg( *args, double ); 243 243 244 unsigned long long digits; 245 digits = val.ull & 0xFFFFFFFFFFFFFULL; // mantisse 246 247 unsigned int base; 248 base = (unsigned int)((val.ull & 0x7FF0000000000000ULL) >> 52); // exp 249 250 unsigned int intp; 251 intp = (unsigned int)val.d; // integer part 252 253 unsigned int decp; // decimal part 254 255 int isvalue = 0; 256 257 if (base == 0x7FF) // special values 258 { 259 if (digits & 0xFFFFFFFFFFFFFULL) // Not a Number 244 unsigned long long mantisse; 245 mantisse = val.ull & 0xFFFFFFFFFFFFFULL; // mantisse 246 247 unsigned int exp; 248 exp = (unsigned int)((val.ull & 0x7FF0000000000000ULL) >> 52); // exp 249 250 if (exp == 0x7FF) // special values 251 { 252 if (mantisse & 0xFFFFFFFFFFFFFULL) // Not a Number 260 253 { 261 254 buf[0] = 'N'; … … 277 270 break; 278 271 } 279 280 if (val.ull & 0x8000000000000000ULL) // negative 272 273 // display sign & analyse overflow 274 unsigned int overflow = 0; 275 if (val.ull & 0x8000000000000000ULL) // negative 281 276 { 282 277 TO_STREAM( '-' ); 283 278 val.d = val.d * -1; 279 if( val.d < -9999999999.0) overflow = 1; 284 280 } 285 281 else // positive 286 282 { 287 283 TO_STREAM( '+' ); 288 } 289 290 if (val.d > 0xFFFFFFFF) // overflow 291 { 292 buf[0] = 'B'; 293 buf[1] = 'I'; 294 buf[2] = 'G'; 284 if( val.d > 9999999999.0) overflow = 1; 285 } 286 287 // check overflow caused by the 10.9 format 288 if ( overflow ) 289 { 290 buf[0] = 'o'; 291 buf[1] = 'v'; 292 buf[2] = 'r'; 295 293 len = 3; 296 294 pbuf = buf; 297 295 break; 298 296 } 299 297 298 // compute integer & decimal parts 299 unsigned int intp; // integer part 300 unsigned int decp; // decimal part 301 intp = (unsigned int)val.d; 300 302 val.d -= (double)intp; 301 303 decp = (unsigned int)(val.d * 1000000000); 302 304 305 // display decimal value in 10.9 format 303 306 for(i = 0; i < 10; i++) 304 307 { 305 if ((!isvalue) && (intp % 10)) isvalue = 1;306 308 buf[9 - i] = HexaTab[intp % 10]; 307 309 if (!(intp /= 10)) break; … … 310 312 len = i+11; 311 313 buf[10] = '.'; 312 313 314 for(i = 0; i < 9; i++) 314 315 { 315 if ((!isvalue) && (decp % 10)) isvalue = 1;316 316 buf[19 - i] = HexaTab[decp % 10]; 317 317 decp /= 10; 318 318 } 319 320 if (!isvalue)321 {322 if (val.d != 0) // underflow323 {324 buf[0] = 'T';325 buf[1] = 'I';326 buf[2] = 'N';327 buf[3] = 'Y';328 len = 4;329 pbuf = buf;330 }331 }332 333 319 break; 334 320 }
Note: See TracChangeset
for help on using the changeset viewer.