This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: cygwin and pow()


Axel Riese <Axel.Riese@risc.uni-linz.ac.at> 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
"gnu-win32-request@cygnus.com" with one line of text: "help".


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]