Subject: RE: cygwin and pow()
From: [email-masked] (Colin Peters)

9 Apr 1998 03:41:50 -0700
Message-ID: <[email-masked]>
Mime-Version: 1.0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
To: "Axel Riese" <[email-masked]>
Cc: "GNU-Win32" <[email-masked]>

Axel Riese <[email-masked]> wrote:
>Could someone please help me with the following problem. I want to compute
>0.5 ^ 0.75, which should give something close to 0.5946...
>
>/*********************************************************************/
>/*                           test.c                                  */
>/*********************************************************************/
>
>int main()
>{
>  double result;
>
>  result = pow(0.5, 0.75);
>  printf("The result is: %f\n", result);
>
>  return 0;
>}
>
>/*********************************************************************/
>
>
>With Cygnus B19.1, I obtain the following:
>
>> test
>The result is: 16416.000000
>
>
>Mingw32 gives:
>
>> test
>The result is: 32.000000
>
>
>Am I doing something wrong ???????????????????

Try adding #include <math.h> to the top of your source file to properly
prototype pow. Also, try compiling with -Wall to get all the warnings
(though I really think the warning about implicit declarations should be on
by default... didn't it used to be?). Compiling my version of your test.c
with -Wall gives the following:

C:\tmp\scratch>gcc -Wall -o test.exe test.c
test.c: In function `main':
test.c:7: warning: implicit declaration of function `pow'
test.c:8: warning: implicit declaration of function `printf'

Problem: implicit declaration of the function pow causes gcc to assume it
returns an int and insert code to convert the int to a double before
assigning it to result, giving you a wrong answer. The output of the program
compiled (with Mingw32 EGCS 1.0.2) with #include <math.h> at the top is

C:\tmp\scratch>test
The result is: 0.594604

-- Colin Peters - colin at fu.is.saga-u.ac.jp
-- Saga Univ. Dept. of Information Science
-- http://www.geocities.com/Tokyo/Towers/6162/index.html
-- http://www.fu.is.saga-u.ac.jp/~colin/index.html

-
For help on using this list (especially unsubscribing), send a message to
"[email-masked]" with one line of text: "help".