www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/01/25/04:49:01

Date: Sun, 25 Jan 1998 11:46:15 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: Jeff Taylor <jltaylor AT cyber-quest DOT com>
cc: djgpp AT delorie DOT com
Subject: Re: math functions
In-Reply-To: <34CA750A.7715@cyber-quest.com>
Message-ID: <Pine.SUN.3.91.980125114225.6225N-100000@is>
MIME-Version: 1.0

On Sat, 24 Jan 1998, Jeff Taylor wrote:

>   For pow(1.000336, -5) I get Infinity.  Is this outside the range of
> pow?
>   For gamma(5) I get 3.178, I'm expecting 24.  Are there two functions
> called gamma functions?

The most probably cause for this seemingly strange behavior is that you 
fail to include <math.h>.  This leaves GCC with no prototype of `pow' and 
`gamma', and so it doesn't convert the integer values like 5 and -5 into 
doubles, which is what these functions expect.  This can certainly produce 
some weird results, and even crash your program.

You should always include <math.h> when you work with math functions.  I 
would also suggest to use double constants, like 5.0 and -5.0, instead of 
integers.  This could save you hours of debugging in some cases.

- Raw text -


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