Mailinglist Archive: opensuse-programming (98 mails)

< Previous Next >
Re: [suse-programming-e] Code produces different results
  • From: Colin Carter <colincarter@xxxxxxxxxxxxxx>
  • Date: Wed, 4 May 2005 19:12:19 +1000
  • Message-id: <200505041912.19751.colincarter@xxxxxxxxxxxxxx>
On Wednesday 04 May 2005 08:12, William A. Mahaffey III wrote:
> Jerry Feldman wrote:
> >On Tuesday 03 May 2005 9:40 am, Davi de Castro Reis wrote:
> >>>Also, you don't mention if you are doing integer or floating point
> >>>math, and what language the code war written in. But, I still would
> >>>suspect that the code has a latent bug.
> >>
> >>I could bet that this is the problem. There are other possibilities, but
> >>this is the most probable cause.
> >>
> >>I think the easiest way to find this kind of errors is to run your code
> >>with some emulator or anything that changes the "memory layout". First
> >>step, use valgrind (developer.kde.org/~sewardj/). Then try electric
> >>fence and similar tools. This should solve the problem. If it doesn't,
> >>well, debug the code in all machines until you get what is wrong.
> >
> >One of the best tools available is IBM Rational's Purify Plus. While
> >valgrind and and electric fence are also good tools, Purify still beats
> >them hands down.
>
Sometimes things are more than they look.
Try computing, to the maximum accuracy:

       x = 10864  y = 18817

        result1 = 9.0*x^4 - y^4 + 2.0*y^2
        result2 = 9.0*x^4 - (y^4 - 2.0*y^2)

        True result is 1

Reference: http://www-anp.lip6.fr/cadna/Examples_Dir/ex1.php

Regards,
Colin



< Previous Next >