vibe-d / vibe.d

Official vibe.d development
MIT License
1.15k stars 284 forks source link

REST client corrupts parameter of type double #1567

Open denizzzka opened 8 years ago

denizzzka commented 8 years ago

Trying to send by client double parameter with value 123.456789.

Client generates HTTP-request:

GET /echo_float8?value_for_echo=123.457 HTTP/1.1

Where value is 123.457

Server also receives 123.457 value instead of 123.456789.

denizzzka commented 8 years ago

client code:

    import vibe.web.rest;

    interface ITest
    {
        string getEchoText(string value_for_echo);
        long getEchoBigint(long value_for_echo);
        double getEchoFloat8(double value_for_echo);
    }

    auto m = new RestInterfaceClient!ITest(httpUrl);

    assert(m.getEchoText("abc") == "abc");
    assert(m.getEchoBigint(123456) == 123456);
    assert(m.getEchoFloat8(123.456789) == 123.456789); // fail
wilzbach commented 7 years ago

@denizzzka this is due to the IEE 754 non-exact way with which float-point numbers are represented. Try the following on your machine:

double d = 123.456789;
writeln(d); // 123.457
denizzzka commented 7 years ago

@wilzbach I am doubt: try to add assert - it isn't fails in these case

assert(d == 123.456789);

writeln(d); // 123.457

writeln just cuts output, IMHO. 6 digits is too small precision, so I think.