Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

Changeset 598

Show
Ignore:
Timestamp:
08/04/10 20:36:31 (14 years ago)
Author:
walter
Message:

bugzilla 4191 [FreeBSD] real constants are rounded to double precision

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/dmd-1.x/src/root/port.c

    r501 r598  
    305305const wchar_t *Port::wlist_separator() 
    306306{ 
    307307    // LOCALE_SLIST for Windows 
    308308    return L","; 
    309309} 
    310310 
    311311char *Port::strupr(char *s) 
    312312{ 
    313313    return ::strupr(s); 
    314314} 
    315315 
    316316#endif 
    317317 
    318318#if linux || __APPLE__ || __FreeBSD__ 
    319319 
    320320#include <math.h> 
    321321#if linux 
    322322#include <bits/nan.h> 
    323323#include <bits/mathdef.h> 
    324324#endif 
     325#if __FreeBSD__ && __i386__ 
     326#include <ieeefp.h> 
     327#endif 
    325328#include <time.h> 
    326329#include <sys/time.h> 
    327330#include <unistd.h> 
    328331#include <stdio.h> 
    329332#include <stdlib.h> 
    330333#include <ctype.h> 
    331334#include <float.h> 
    332335 
    333336static double zero = 0; 
    334337double Port::nan = NAN; 
    335338double Port::infinity = 1 / zero; 
    336339double Port::dbl_max = 1.7976931348623157e308; 
    337340double Port::dbl_min = 5e-324; 
    338341long double Port::ldbl_max = LDBL_MAX; 
    339342 
    340343struct PortInitializer 
    341344{ 
    342345    PortInitializer(); 
    343346}; 
    344347 
    345348static PortInitializer portinitializer; 
    346349 
    347350PortInitializer::PortInitializer() 
    348351{ 
    349352    // gcc nan's have the sign bit set by default, so turn it off 
    350353    // Need the volatile to prevent gcc from doing incorrect 
    351354    // constant folding. 
    352355    volatile long double foo; 
    353356    foo = NAN; 
    354357    if (signbit(foo))   // signbit sometimes, not always, set 
    355358        foo = -foo;     // turn off sign bit 
    356359    Port::nan = foo; 
    357360 
    358 #if __FreeBSD__ 
     361#if __FreeBSD__ && __i386__ 
    359362    // LDBL_MAX comes out as infinity. Fix. 
    360363    static unsigned char x[sizeof(long double)] = 
    361364        { 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0x7F }; 
    362365    Port::ldbl_max = *(long double *)&x[0]; 
     366    // FreeBSD defaults to double precision. Switch to extended precision. 
     367    fpsetprec(FP_PE); 
    363368#endif 
    364369} 
    365370 
    366371#undef isnan 
    367372int Port::isNan(double r) 
    368373{ 
    369374#if __APPLE__ 
    370375    return __inline_isnan(r); 
    371376#else 
    372377    return ::isnan(r); 
    373378#endif 
    374379} 
    375380 
    376381int Port::isNan(long double r) 
    377382{ 
    378383#if __APPLE__ 
    379384    return __inline_isnan(r); 
    380385#else 
    381386    return ::isnan(r); 
    382387#endif 
  • trunk/src/mtype.c

    r578 r598  
    25282528            case Tuns8:         ivalue = 0xFF;          goto Livalue; 
    25292529            case Tint16:        ivalue = 0x7FFFUL;      goto Livalue; 
    25302530            case Tuns16:        ivalue = 0xFFFFUL;      goto Livalue; 
    25312531            case Tint32:        ivalue = 0x7FFFFFFFUL;  goto Livalue; 
    25322532            case Tuns32:        ivalue = 0xFFFFFFFFUL;  goto Livalue; 
    25332533            case Tint64:        ivalue = 0x7FFFFFFFFFFFFFFFLL;  goto Livalue; 
    25342534            case Tuns64:        ivalue = 0xFFFFFFFFFFFFFFFFULL; goto Livalue; 
    25352535            case Tbool:         ivalue = 1;             goto Livalue; 
    25362536            case Tchar:         ivalue = 0xFF;          goto Livalue; 
    25372537            case Twchar:        ivalue = 0xFFFFUL;      goto Livalue; 
    25382538            case Tdchar:        ivalue = 0x10FFFFUL;    goto Livalue; 
    25392539 
    25402540            case Tcomplex32: 
    25412541            case Timaginary32: 
    25422542            case Tfloat32:      fvalue = FLT_MAX;       goto Lfvalue; 
    25432543            case Tcomplex64: 
    25442544            case Timaginary64: 
    25452545            case Tfloat64:      fvalue = DBL_MAX;       goto Lfvalue; 
    25462546            case Tcomplex80: 
    25472547            case Timaginary80: 
    2548             case Tfloat80:      fvalue = LDBL_MAX;      goto Lfvalue; 
     2548            case Tfloat80:      fvalue = Port::ldbl_max; goto Lfvalue; 
    25492549        } 
    25502550    } 
    25512551    else if (ident == Id::min) 
    25522552    { 
    25532553        switch (ty) 
    25542554        { 
    25552555            case Tint8:         ivalue = -128;          goto Livalue; 
    25562556            case Tuns8:         ivalue = 0;             goto Livalue; 
    25572557            case Tint16:        ivalue = -32768;        goto Livalue; 
    25582558            case Tuns16:        ivalue = 0;             goto Livalue; 
    25592559            case Tint32:        ivalue = -2147483647L - 1;      goto Livalue; 
    25602560            case Tuns32:        ivalue = 0;                     goto Livalue; 
    25612561            case Tint64:        ivalue = (-9223372036854775807LL-1LL);  goto Livalue; 
    25622562            case Tuns64:        ivalue = 0;             goto Livalue; 
    25632563            case Tbool:         ivalue = 0;             goto Livalue; 
    25642564            case Tchar:         ivalue = 0;             goto Livalue; 
    25652565            case Twchar:        ivalue = 0;             goto Livalue; 
    25662566            case Tdchar:        ivalue = 0;             goto Livalue; 
    25672567 
    25682568            case Tcomplex32: 
  • trunk/src/root/port.c

    r501 r598  
    305305const wchar_t *Port::wlist_separator() 
    306306{ 
    307307    // LOCALE_SLIST for Windows 
    308308    return L","; 
    309309} 
    310310 
    311311char *Port::strupr(char *s) 
    312312{ 
    313313    return ::strupr(s); 
    314314} 
    315315 
    316316#endif 
    317317 
    318318#if linux || __APPLE__ || __FreeBSD__ 
    319319 
    320320#include <math.h> 
    321321#if linux 
    322322#include <bits/nan.h> 
    323323#include <bits/mathdef.h> 
    324324#endif 
     325#if __FreeBSD__ && __i386__ 
     326#include <ieeefp.h> 
     327#endif 
    325328#include <time.h> 
    326329#include <sys/time.h> 
    327330#include <unistd.h> 
    328331#include <stdio.h> 
    329332#include <stdlib.h> 
    330333#include <ctype.h> 
    331334#include <float.h> 
    332335 
    333336static double zero = 0; 
    334337double Port::nan = NAN; 
    335338double Port::infinity = 1 / zero; 
    336339double Port::dbl_max = 1.7976931348623157e308; 
    337340double Port::dbl_min = 5e-324; 
    338341long double Port::ldbl_max = LDBL_MAX; 
    339342 
    340343struct PortInitializer 
    341344{ 
    342345    PortInitializer(); 
    343346}; 
    344347 
    345348static PortInitializer portinitializer; 
    346349 
    347350PortInitializer::PortInitializer() 
    348351{ 
    349352    // gcc nan's have the sign bit set by default, so turn it off 
    350353    // Need the volatile to prevent gcc from doing incorrect 
    351354    // constant folding. 
    352355    volatile long double foo; 
    353356    foo = NAN; 
    354357    if (signbit(foo))   // signbit sometimes, not always, set 
    355358        foo = -foo;     // turn off sign bit 
    356359    Port::nan = foo; 
    357360 
    358 #if __FreeBSD__ 
     361#if __FreeBSD__ && __i386__ 
    359362    // LDBL_MAX comes out as infinity. Fix. 
    360363    static unsigned char x[sizeof(long double)] = 
    361364        { 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0x7F }; 
    362365    Port::ldbl_max = *(long double *)&x[0]; 
     366    // FreeBSD defaults to double precision. Switch to extended precision. 
     367    fpsetprec(FP_PE); 
    363368#endif 
    364369} 
    365370 
    366371#undef isnan 
    367372int Port::isNan(double r) 
    368373{ 
    369374#if __APPLE__ 
    370375    return __inline_isnan(r); 
    371376#else 
    372377    return ::isnan(r); 
    373378#endif 
    374379} 
    375380 
    376381int Port::isNan(long double r) 
    377382{ 
    378383#if __APPLE__ 
    379384    return __inline_isnan(r); 
    380385#else 
    381386    return ::isnan(r); 
    382387#endif