delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/01/27/02:27:41

Sender: M DOT A DOT Bukin AT inp DOT nsk DOT su
To: djgpp AT delorie DOT com
Subject: Re: math functions
References: <34CA750A DOT 7715 AT cyber-quest DOT com>
Reply-To: M DOT A DOT Bukin AT inp DOT nsk DOT su
From: M DOT A DOT Bukin AT inp DOT nsk DOT su
Date: 27 Jan 1998 13:26:23 +0600
In-Reply-To: Jeff Taylor's message of Sat, 24 Jan 1998 18:11:06 -0500
Message-Id: <20u3aq9y3k.fsf@Sky.inp.nsk.su>
Lines: 38

Jeff Taylor <jltaylor AT cyber-quest DOT com> writes:

> The gamma and pow functions
> are not giving me the answers I expect.
>   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?

  I think, you forgot to include apropriate header files.

Here is correct program (except for typos):

---
#include <math.h>
#include <stdio.h>

int
main (void)
{
  printf ("%g\n", pow (1.000336, -5));
  printf ("%g\n", gamma (5)); /* I get 3.17805 here.  */
  printf ("%g\n", exp (gamma (5))); /* This one gives 24.  */
  return 0;
}
---

One more thing -- I think it is not DJGPP specific, but a general C
question, so comp.lang.c is more apropriate.

To make it closer to DJGPP, try to remove `#include <math.h>' and run
gcc with `-Wall' switch (and then always use -Wall for compiling your
programs, let compiler catch your mistakes).

BTW, I have not DJGPP references for libc, but man page on Unix here
says that gamma(x) returns ln|GAMMA(x)|, where GAMMA is the
mathematical gamma function (gamma is not in libc and may not be
documented in DJGPP libc references).

- Raw text -


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