needing help with: Floating point error

Torbjorn Granlund tg at gmplib.org
Sun Jun 28 23:59:33 CEST 2009


jmonetti at uncu.edu.ar writes:

  I'm experiencing a little problem with gmp, and hope
  you can help me.
  I tried to simplify my code and show you (below).  :)
  
  The code declare some gmp variables, initializes,
  and then start an iteration calculating the following
  equations:
  
  
       d    = a + pow(0.05 , k );
       prod =(a*e)-(d*b);
       X    =(c*e-f*b)/prod;
       Y    =(a*f-d*c)/prod;
  
  In each iteration k is incremented, so the pow
  function returns values even smaller.
  Finally it must operate with both big values,
  and small values.
  
  The problem I found that the program get a
  Floating Point in iteration 29 (with my computer/
  arquitectura/compiler/...).
  
  Can you give me some help with it ?
  Attached a simplified code and ouput.
  
Unfortunately, your code is simplified to the point where it cannot be
compiled.  There is no main, nor any function header for the function
you're having problem with.  I don't see the line where you setup the
precision, which is critical.

Have you tried to debug your program, to see what operation actually
performs a division by zero?  I strongly suspect that you get
cancellation in the subtract assigning to prod, resulting in that prod
becomes zero.  Then the division will blow up.

But this is just a guess.  I quick session in a debugger should give you
the facts.

-- 
Torbjörn


More information about the gmp-discuss mailing list