delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1995/05/30/18:54:43

From: Larry Estep <ljeste01 AT msuacad DOT morehead-st DOT edu>
Subject: Math/rounding errors?
To: djgpp AT sun DOT soe DOT clarkson DOT edu
Date: Tue, 30 May 95 17:15:34 EDT
Mailer: Elm [revision: 70.85.2.1]


    I have a piece of code that implements the gamma function.  It works
fine with Borland C, as well as with the C compiler on the HP Unix machine
I use at work.  But when compiled under djgpp, I seem to be getting some
sort of rounding error.
    For instance, passing 5.0 to the function should result in a value
of 120.0.  Instead I get 118.401 from the djgpp version.  This is just
not acceptable.
    The code for the function is fairly simple.  It involves a few
multiplications and divisions, and one call to exp().  There are no
iterative loops to build up roundoff errors.  And even if there were,
I wouldn't expect it to be this severe.
    I've also made sure that all computations are being done with doubles.
I even went so far as to assign all of the constants to a variable.  I even
type casted them just to make sure!  For example:
    double one = (double) 1.0;

    I feel like I must be missing something fundamental.  But I've looked
at the FAQ, and I've looked at the docs for gcc, and I can't find anything
that addresses the problem I'm having.
    I would really appreciate it if someone could shed some light on this
for me.  

Thanks,
Larry

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019