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

Changeset 1914

Show
Ignore:
Timestamp:
08/22/10 01:54:08 (14 years ago)
Author:
dsimcha
Message:

Bug 4700: to!float("0") fails

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/docsrc/changelog.dd

    r1908 r1914  
    3838    $(LI $(BUGZILLA 4345): More flexible std.array.array.) 
    3939    $(LI $(BUGZILLA 4363): Some phobos ranges are not forward ranges (but should be).) 
    4040    $(LI $(BUGZILLA 4381): Length attribute for std.typecons.Tuple.) 
    4141    $(LI $(BUGZILLA 4387): std.range.Cycle assumes lvalue elements.) 
    4242    $(LI $(BUGZILLA 4388): std.range.Radial assumes lvalue elements.) 
    4343    $(LI $(BUGZILLA 4403): std.range.FrontTransversal assumes lvalue elements.) 
    4444    $(LI $(BUGZILLA 4404): std.range.Transversal assumes lvalue elements.) 
    4545    $(LI $(BUGZILLA 4455): Taking the sqrt of an integer shouldn't require an explicit cast.) 
    4646    $(LI $(BUGZILLA 4464): std.range.take does not always return Take!R.) 
    4747    $(LI $(BUGZILLA 4603): array(iota(1, 0)) error.) 
     48    $(LI $(BUGZILLA 4700): to!float("0") fails) 
    4849    ) 
    4950) 
    5051 
    5152 
    5253<div id=version> 
    5354$(UL 
    5455    $(NEW 049) 
    5556    $(NEW 048) 
    5657    $(NEW 047) 
    5758    $(NEW 046) 
  • trunk/phobos/std/conv.d

    r1895 r1914  
    12251225    } 
    12261226    char sign = 0;                       /* indicating +                 */ 
    12271227    switch (p.front) 
    12281228    { 
    12291229        case '-': sign++; goto case '+'; 
    12301230        case '+': p.popFront(); enforce(!p.empty, 
    12311231                new ConvError("error converting input to floating point")); 
    12321232        default: {} 
    12331233    } 
    12341234 
    1235     const bool isHex = p.front == '0' 
    1236         && (p.popFront(), p.front == 'x' || p.front == 'X'); 
     1235    bool isHex = p.front == '0'; 
     1236    if(isHex) 
     1237    { 
     1238        p.popFront(); 
     1239        if(p.empty) 
     1240        { 
     1241            return (sign) ? -0 : 0; 
     1242        } 
     1243 
     1244        isHex = isHex && (p.front == 'x' || p.front == 'X'); 
     1245    } 
    12371246 
    12381247    real ldval = 0.0; 
    12391248    char dot = 0;                        /* if decimal point has been seen */ 
    12401249    int exp = 0; 
    12411250    long msdec = 0, lsdec = 0; 
    12421251    ulong msscale = 1; 
    12431252 
    12441253    if (isHex) 
    12451254    { 
    12461255        int guard = 0; 
     
    22812290    f = to!float( "123e+2" ); 
    22822291    assert( f == 123e+2f ); 
    22832292 
    22842293    f = to!float( "123e-2" ); 
    22852294    assert( f == 123e-2f ); 
    22862295    f = to!float( "123." ); 
    22872296    assert( f == 123.f ); 
    22882297    f = to!float( ".456" ); 
    22892298    assert( f == .456f ); 
    22902299 
     2300    assert(to!float("0") == 0f); 
     2301    assert(to!float("-0") == -0f); 
     2302 
    22912303    // min and max 
    22922304    try 
    22932305    { 
    22942306        f = to!float("1.17549e-38"); 
    22952307        assert(feq(cast(real)f, cast(real)1.17549e-38)); 
    22962308        assert(feq(cast(real)f, cast(real)float.min_normal)); 
    22972309        f = to!float("3.40282e+38"); 
    22982310        assert(to!string(f) == to!string(3.40282e+38)); 
    22992311    } 
    23002312    catch (ConvError e) // strtof() bug on some platforms 
     
    23392351    assert( d == 123e2); 
    23402352    d = to!double( "123e-2" ); 
    23412353    assert( d == 123e-2 ); 
    23422354    d = to!double( "123." ); 
    23432355    assert( d == 123. ); 
    23442356    d = to!double( ".456" ); 
    23452357    assert( d == .456 ); 
    23462358    d = to!double( "1.23456E+2" ); 
    23472359    assert( d == 1.23456E+2 ); 
    23482360 
     2361    assert(to!double("0") == 0.0); 
     2362    assert(to!double("-0") == -0.0); 
     2363 
    23492364    // min and max 
    23502365    try 
    23512366    { 
    23522367        d = to!double("2.22508e-308"); 
    23532368        assert(feq(cast(real)d, cast(real)2.22508e-308)); 
    23542369        assert(feq(cast(real)d, cast(real)double.min_normal)); 
    23552370        d = to!double("1.79769e+308"); 
    23562371        assert(to!string(d) == to!string(1.79769e+308)); 
    23572372        assert(to!string(d) == to!string(double.max)); 
    23582373    } 
     
    24002415    assert(feq(r, 1.23L)); 
    24012416    r = to!real("123."); 
    24022417    assert(r == 123L); 
    24032418    r = to!real(".456"); 
    24042419    assert(r == .456L); 
    24052420 
    24062421    r = to!real("1.23456e+2"); 
    24072422    assert(feq(r,  1.23456e+2L)); 
    24082423    r = to!real(to!string(real.max / 2L)); 
    24092424    assert(to!string(r) == to!string(real.max / 2L)); 
     2425 
     2426    assert(to!real("0") == 0.0L); 
     2427    assert(to!real("-0") == -0.0L); 
    24102428 
    24112429    // min and max 
    24122430    try 
    24132431    { 
    24142432        r = to!real(to!string(real.min_normal)); 
    24152433        assert(to!string(r) == to!string(real.min_normal)); 
    24162434        r = to!real(to!string(real.max)); 
    24172435        assert(to!string(r) == to!string(real.max)); 
    24182436    } 
    24192437    catch (ConvError e) // strtold() bug on some platforms