in reply to Re^2: test fails on 64bit uselongdouble Perl
in thread test fails on 64bit uselongdouble Perl

Then you have to avoid all floating point numbers. But seriously, that's not a worthy goal. If your algorithms are numerically stable, the errors won't be larger than 1e-18 or so - does that really matter for your purposes?

Replies are listed 'Best First'.
Re^4: test fails on 64bit uselongdouble Perl
by frankcox (Acolyte) on Oct 29, 2009 at 20:04 UTC

    I need an integer result and it needs to be the same integer for any Perl. My problem with uselongdouble Perls is that the result for most values is the same but for some it's off by one, sometimes high and sometimes low.

    If you're interested, I've included more detail in this RT ticket:

    http://rt.cpan.org/Ticket/Display.html?id=50820
Re^4: test fails on 64bit uselongdouble Perl
by frankcox (Acolyte) on Oct 29, 2009 at 19:47 UTC
    My result needs to be an integer and it needs to be the same integer for all Perls. My problem with uselongdouble Perls is that for some values the result is off by one. Sometimes it's one to big and sometimes one to small.

      Sometimes it's one to big and sometimes one to small.

      Right now, you are truncating the numbers. That means you are introducing an error as big as 1.0

      $ perl -e'printf "%d\n", $_ for 4.9999999999, 5' 4 5

      You need to round instead.

      $ perl -e'printf "%.0f\n", $_ for 4.9999999999, 5' 5 5

      But that's not good enough either.

      $ perl -e'printf "%.0f\n", $_ for 5.4999999999, 5.5' 5 6

      You need to round to your tolerance first.

      $ perl -e'printf "%.0f\n", sprintf "%.8f", $_ for 5.4999999999, 5.5' 6 6
        $ perl -e'printf "%.0f\n", $_ for 5.4999999999, 5.5' 5 6

        I don't get what's the problem with the above. The output is what I would expect.