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

Changeset 1557

Show
Ignore:
Timestamp:
05/26/10 05:59:52 (15 years ago)
Author:
rsinfu
Message:

We should not expect exact precision of strtold().
The precition may vary between platforms or even different versions of libc.

Tested on FreeBSD and Gentoo Linux with dmd r501.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/phobos/std/conv.d

    r1513 r1557  
    18721872    assert( f == 123e+2f ); 
    18731873 
    18741874    f = to!float( "123e-2" ); 
    18751875    assert( f == 123e-2f ); 
    18761876    f = to!float( "123." ); 
    18771877    assert( f == 123.f ); 
    18781878    f = to!float( ".456" ); 
    18791879    assert( f == .456f ); 
    18801880 
    18811881    // min and max 
    1882     f = to!float("1.17549435e-38"); 
    1883     assert(feq(cast(real)f, cast(real)1.17549e-38)); 
     1882    f = to!float("1.1755e-38"); 
     1883    assert(feq(cast(real)f, cast(real)1.1755e-38)); 
    18841884    assert(feq(cast(real)f, cast(real)float.min_normal)); 
    1885     f = to!float("3.40282347e+38"); 
    1886     assert(to!string(f) == to!string(3.40282e+38)); 
     1885    f = to!float("3.4028e+38"); 
     1886    assert(to!string(f) == to!string(3.4028e+38)); 
    18871887 
    18881888    // nan 
    18891889    f = to!float("nan"); 
    18901890    assert(to!string(f) == to!string(float.nan)); 
    18911891 
    18921892    bool ok = false; 
    18931893    try 
    18941894    { 
    18951895        to!float("\x00"); 
    18961896    } 
     
    19211921    d = to!double( "123e-2" ); 
    19221922    assert( d == 123e-2 ); 
    19231923    d = to!double( "123." ); 
    19241924    assert( d == 123. ); 
    19251925    d = to!double( ".456" ); 
    19261926    assert( d == .456 ); 
    19271927    d = to!double( "1.23456E+2" ); 
    19281928    assert( d == 1.23456E+2 ); 
    19291929 
    19301930    // min and max 
    1931     d = to!double("2.2250738585072014e-308"); 
    1932     assert(feq(cast(real)d, cast(real)2.22508e-308)); 
     1931    d = to!double("2.2251e-308"); 
     1932    assert(feq(cast(real)d, cast(real)2.2251e-308)); 
    19331933    assert(feq(cast(real)d, cast(real)double.min_normal)); 
    1934     d = to!double("1.7976931348623157e+308"); 
    1935     assert(to!string(d) == to!string(1.79769e+308)); 
    1936     assert(to!string(d) == to!string(double.max)); 
     1934    d = to!double("1.7976e+308"); 
     1935    assert(to!string(d) == to!string(1.7976e+308)); 
    19371936 
    19381937    // nan 
    19391938    d = to!double("nan"); 
    19401939    assert(to!string(d) == to!string(double.nan)); 
    19411940    //assert(cast(real)d == cast(real)double.nan); 
    19421941 
    19431942    bool ok = false; 
    19441943    try 
    19451944    { 
    19461945        to!double("\x00"); 
     
    19661965    assert(r == 123L); 
    19671966    r = to!real("-123"); 
    19681967    assert(r == -123L); 
    19691968    r = to!real("123e2"); 
    19701969    assert(feq(r, 123e2L)); 
    19711970    r = to!real("123e-2"); 
    19721971    assert(feq(r, 1.23L)); 
    19731972    r = to!real("123."); 
    19741973    assert(r == 123L); 
    19751974    r = to!real(".456"); 
    1976     assert(r == .456L); 
     1975    assert(feq(r, .456L)); 
    19771976 
    19781977    r = to!real("1.23456e+2"); 
    19791978    assert(feq(r,  1.23456e+2L)); 
    19801979    r = to!real(to!string(real.max / 2L)); 
    19811980    assert(to!string(r) == to!string(real.max / 2L)); 
    19821981 
    19831982    // min and max 
    1984     version (FreeBSD) 
    1985     { 
    1986         // BSD libc strtold() does a poor job on min/max values. 
    1987         writefln(" --- std.conv(%s) skipping tests on real.min_normal and real.max ---", __LINE__); 
    1988     } 
    1989     else 
     1983    version (Libc_ExactStrtold) 
    19901984    { 
    19911985        r = to!real(to!string(real.min_normal)); 
    19921986        assert(to!string(r) == to!string(real.min_normal)); 
    19931987        r = to!real(to!string(real.max)); 
    19941988        assert(to!string(r) == to!string(real.max)); 
    19951989    } 
    19961990 
    19971991    // nan 
    19981992    r = to!real("nan"); 
    19991993    assert(to!string(r) == to!string(real.nan)); 
  • trunk/phobos/std/getopt.d

    r1500 r1557  
    576576    getopt(args, "output", &outputFiles); 
    577577    assert(outputFiles.length == 2 
    578578           && outputFiles[0] == "myfile.txt" && outputFiles[0] == "myfile.txt"); 
    579579 
    580580    args = (["program.name", "--tune=alpha=0.5", 
    581581             "--tune", "beta=0.6"]).dup; 
    582582    double[string] tuningParms; 
    583583    getopt(args, "tune", &tuningParms); 
    584584    assert(args.length == 1); 
    585585    assert(tuningParms.length == 2); 
    586     assert(tuningParms["alpha"] == 0.5); 
    587     assert(tuningParms["beta"] == 0.6); 
     586    assert(0.4999 < tuningParms["alpha"] && tuningParms["alpha"] < 0.5001); 
     587    assert(0.5999 < tuningParms["beta"] && tuningParms["beta"] < 0.6001); 
    588588 
    589589    uint verbosityLevel = 1; 
    590590    void myHandler(string option) 
    591591    { 
    592592        if (option == "quiet") 
    593593        { 
    594594            verbosityLevel = 0; 
    595595        } 
    596596        else 
    597597        {