Changeset 598
- Timestamp:
- 08/04/10 20:36:31 (14 years ago)
- Files:
-
- branches/dmd-1.x/src/root/port.c (modified) (1 diff)
- trunk/src/mtype.c (modified) (1 diff)
- trunk/src/root/port.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/dmd-1.x/src/root/port.c
r501 r598 305 305 const wchar_t *Port::wlist_separator() 306 306 { 307 307 // LOCALE_SLIST for Windows 308 308 return L","; 309 309 } 310 310 311 311 char *Port::strupr(char *s) 312 312 { 313 313 return ::strupr(s); 314 314 } 315 315 316 316 #endif 317 317 318 318 #if linux || __APPLE__ || __FreeBSD__ 319 319 320 320 #include <math.h> 321 321 #if linux 322 322 #include <bits/nan.h> 323 323 #include <bits/mathdef.h> 324 324 #endif 325 #if __FreeBSD__ && __i386__ 326 #include <ieeefp.h> 327 #endif 325 328 #include <time.h> 326 329 #include <sys/time.h> 327 330 #include <unistd.h> 328 331 #include <stdio.h> 329 332 #include <stdlib.h> 330 333 #include <ctype.h> 331 334 #include <float.h> 332 335 333 336 static double zero = 0; 334 337 double Port::nan = NAN; 335 338 double Port::infinity = 1 / zero; 336 339 double Port::dbl_max = 1.7976931348623157e308; 337 340 double Port::dbl_min = 5e-324; 338 341 long double Port::ldbl_max = LDBL_MAX; 339 342 340 343 struct PortInitializer 341 344 { 342 345 PortInitializer(); 343 346 }; 344 347 345 348 static PortInitializer portinitializer; 346 349 347 350 PortInitializer::PortInitializer() 348 351 { 349 352 // gcc nan's have the sign bit set by default, so turn it off 350 353 // Need the volatile to prevent gcc from doing incorrect 351 354 // constant folding. 352 355 volatile long double foo; 353 356 foo = NAN; 354 357 if (signbit(foo)) // signbit sometimes, not always, set 355 358 foo = -foo; // turn off sign bit 356 359 Port::nan = foo; 357 360 358 #if __FreeBSD__ 361 #if __FreeBSD__ && __i386__ 359 362 // LDBL_MAX comes out as infinity. Fix. 360 363 static unsigned char x[sizeof(long double)] = 361 364 { 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0x7F }; 362 365 Port::ldbl_max = *(long double *)&x[0]; 366 // FreeBSD defaults to double precision. Switch to extended precision. 367 fpsetprec(FP_PE); 363 368 #endif 364 369 } 365 370 366 371 #undef isnan 367 372 int Port::isNan(double r) 368 373 { 369 374 #if __APPLE__ 370 375 return __inline_isnan(r); 371 376 #else 372 377 return ::isnan(r); 373 378 #endif 374 379 } 375 380 376 381 int Port::isNan(long double r) 377 382 { 378 383 #if __APPLE__ 379 384 return __inline_isnan(r); 380 385 #else 381 386 return ::isnan(r); 382 387 #endif trunk/src/mtype.c
r578 r598 2528 2528 case Tuns8: ivalue = 0xFF; goto Livalue; 2529 2529 case Tint16: ivalue = 0x7FFFUL; goto Livalue; 2530 2530 case Tuns16: ivalue = 0xFFFFUL; goto Livalue; 2531 2531 case Tint32: ivalue = 0x7FFFFFFFUL; goto Livalue; 2532 2532 case Tuns32: ivalue = 0xFFFFFFFFUL; goto Livalue; 2533 2533 case Tint64: ivalue = 0x7FFFFFFFFFFFFFFFLL; goto Livalue; 2534 2534 case Tuns64: ivalue = 0xFFFFFFFFFFFFFFFFULL; goto Livalue; 2535 2535 case Tbool: ivalue = 1; goto Livalue; 2536 2536 case Tchar: ivalue = 0xFF; goto Livalue; 2537 2537 case Twchar: ivalue = 0xFFFFUL; goto Livalue; 2538 2538 case Tdchar: ivalue = 0x10FFFFUL; goto Livalue; 2539 2539 2540 2540 case Tcomplex32: 2541 2541 case Timaginary32: 2542 2542 case Tfloat32: fvalue = FLT_MAX; goto Lfvalue; 2543 2543 case Tcomplex64: 2544 2544 case Timaginary64: 2545 2545 case Tfloat64: fvalue = DBL_MAX; goto Lfvalue; 2546 2546 case Tcomplex80: 2547 2547 case Timaginary80: 2548 case Tfloat80: fvalue = LDBL_MAX;goto Lfvalue;2548 case Tfloat80: fvalue = Port::ldbl_max; goto Lfvalue; 2549 2549 } 2550 2550 } 2551 2551 else if (ident == Id::min) 2552 2552 { 2553 2553 switch (ty) 2554 2554 { 2555 2555 case Tint8: ivalue = -128; goto Livalue; 2556 2556 case Tuns8: ivalue = 0; goto Livalue; 2557 2557 case Tint16: ivalue = -32768; goto Livalue; 2558 2558 case Tuns16: ivalue = 0; goto Livalue; 2559 2559 case Tint32: ivalue = -2147483647L - 1; goto Livalue; 2560 2560 case Tuns32: ivalue = 0; goto Livalue; 2561 2561 case Tint64: ivalue = (-9223372036854775807LL-1LL); goto Livalue; 2562 2562 case Tuns64: ivalue = 0; goto Livalue; 2563 2563 case Tbool: ivalue = 0; goto Livalue; 2564 2564 case Tchar: ivalue = 0; goto Livalue; 2565 2565 case Twchar: ivalue = 0; goto Livalue; 2566 2566 case Tdchar: ivalue = 0; goto Livalue; 2567 2567 2568 2568 case Tcomplex32: trunk/src/root/port.c
r501 r598 305 305 const wchar_t *Port::wlist_separator() 306 306 { 307 307 // LOCALE_SLIST for Windows 308 308 return L","; 309 309 } 310 310 311 311 char *Port::strupr(char *s) 312 312 { 313 313 return ::strupr(s); 314 314 } 315 315 316 316 #endif 317 317 318 318 #if linux || __APPLE__ || __FreeBSD__ 319 319 320 320 #include <math.h> 321 321 #if linux 322 322 #include <bits/nan.h> 323 323 #include <bits/mathdef.h> 324 324 #endif 325 #if __FreeBSD__ && __i386__ 326 #include <ieeefp.h> 327 #endif 325 328 #include <time.h> 326 329 #include <sys/time.h> 327 330 #include <unistd.h> 328 331 #include <stdio.h> 329 332 #include <stdlib.h> 330 333 #include <ctype.h> 331 334 #include <float.h> 332 335 333 336 static double zero = 0; 334 337 double Port::nan = NAN; 335 338 double Port::infinity = 1 / zero; 336 339 double Port::dbl_max = 1.7976931348623157e308; 337 340 double Port::dbl_min = 5e-324; 338 341 long double Port::ldbl_max = LDBL_MAX; 339 342 340 343 struct PortInitializer 341 344 { 342 345 PortInitializer(); 343 346 }; 344 347 345 348 static PortInitializer portinitializer; 346 349 347 350 PortInitializer::PortInitializer() 348 351 { 349 352 // gcc nan's have the sign bit set by default, so turn it off 350 353 // Need the volatile to prevent gcc from doing incorrect 351 354 // constant folding. 352 355 volatile long double foo; 353 356 foo = NAN; 354 357 if (signbit(foo)) // signbit sometimes, not always, set 355 358 foo = -foo; // turn off sign bit 356 359 Port::nan = foo; 357 360 358 #if __FreeBSD__ 361 #if __FreeBSD__ && __i386__ 359 362 // LDBL_MAX comes out as infinity. Fix. 360 363 static unsigned char x[sizeof(long double)] = 361 364 { 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0x7F }; 362 365 Port::ldbl_max = *(long double *)&x[0]; 366 // FreeBSD defaults to double precision. Switch to extended precision. 367 fpsetprec(FP_PE); 363 368 #endif 364 369 } 365 370 366 371 #undef isnan 367 372 int Port::isNan(double r) 368 373 { 369 374 #if __APPLE__ 370 375 return __inline_isnan(r); 371 376 #else 372 377 return ::isnan(r); 373 378 #endif 374 379 } 375 380 376 381 int Port::isNan(long double r) 377 382 { 378 383 #if __APPLE__ 379 384 return __inline_isnan(r); 380 385 #else 381 386 return ::isnan(r); 382 387 #endif
