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

Ahh! Good explanation of issue with .6 ikegami. I missed that

My real problem is that I get different results with different Perl variants. I need my algorithm to work the same on all Perls.

  • Comment on Re^2: test fails on 64bit uselongdouble Perl

Replies are listed 'Best First'.
Re^3: test fails on 64bit uselongdouble Perl
by moritz (Cardinal) on Oct 29, 2009 at 19:30 UTC
    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?
      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

      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^3: test fails on 64bit uselongdouble Perl
by ikegami (Patriarch) on Oct 29, 2009 at 20:31 UTC

    You can't use floats if differences are a problem. Like I said, with floats, you have to be satisfied with no differences within a tolerance.

      The output of my algorithm is an integer. On all other Perls tested by CPAN Testers I get the same integer. On uselongdouble Perls I usually get the same int too, but for some values I get an integer that is one off, sometimes high and sometime low. It's really just a a lucky fluke that a test happened to use a value that uncovered the bug

      I may have to remove support for these "problem" Perls by aborting the build. I'd rather not do that but it's better than giving wrong results

      If you're interested, there are more details in this RT ticket:

      http://rt.cpan.org/Ticket/Display.html?id=50820
        The output of my algorithm is an integer

        That makes things much easier. You can always just round to the nearest integer at the end, and as long as the numeric error is less than 0.5 you still get the same result.

        Perl 6 - links to (nearly) everything that is Perl 6.

        The output of my algorithm is an integer.

        So?

        I'd rather not do that but it's better than giving wrong results

        There's another alternative: Fixing your bug.