Some math functions return results that are not correct when you compile them by using the gcc compiler tool in Windows Services for UNIX 3.5 (891755)



The information in this article applies to:

  • Microsoft Windows Services for UNIX 3.5


SYMPTOMS

When you compile a program by using the gcc C language compiler tool that is included in the Microsoft Interix software development kit (SDK) on Microsoft Windows Services for UNIX 3.5, some math functions, such as the hypot function, may return results that are not correct.

CAUSE

This problem occurs because the math function that is used is not declared in the source code. By default, the function will return an integer (int) value when this problem occurs, instead of the correct data type value.

Note This problem occurs even when you include the math.h header file in the source code. Because Windows Services for UNIX 3.5 follows the POSIX standard, function declarations that do not comply with the POSIX standard are ignored.

RESOLUTION

To resolve this problem, follow these steps:
  1. Define the _ALL_SOURCE macro in your source code, and then include the math.h header file in your source code. For example, you can add an _ALL_SOURCE macro value of 1 before the math.h header file in your source code:

    #define _ALL_SOURCE 1
    #include <math.h>
  2. Compile the source code by using the gcc compiler tool.

MORE INFORMATION

For more information about Interix code conversion, visit the following Microsoft Web site:

Steps to reproduce the problem

  1. Install the Interix SDK from your Windows Services for UNIX 3.5 CD.
  2. Save the following source code to a text file, and name the file test.c:

    #include <math.h>
    main()
    {
    double a = 0.0;
    double b = 0.0;
    
    double x = hypot(a,b);
    
    printf("hypot = %e\n", x);
    }
  3. Type gcc test.c -lm at a command prompt, and then press ENTER.
  4. Type ./a.out at a command prompt, and then press ENTER.
The result that you receive is hypot = 1.459200e+04, but the correct result is hypot = 0.000000e+00.

Modification Type:MajorLast Reviewed:1/20/2005
Keywords:kbtshoot kbprb KB891755 kbAudDeveloper