Microsoft KB Archive/891755

= 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 =

Article ID: 891755

Article Last Modified on 3/14/2007

-

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:   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 Compile the source code by using the gcc compiler tool.
 * 1) include  



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

http://msdn2.microsoft.com/en-us/library/ms811897.aspx

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

<pre class="fixed_text">#include <math.h> main { double a = 0.0; double b = 0.0;

double x = hypot(a,b);

printf(&quot;hypot = %e\n&quot;, x); } </li> Type gcc test.c -lm at a command prompt, and then press ENTER.</li> Type ./a.out at a command prompt, and then press ENTER.</li></ol>

The result that you receive is hypot = 1.459200e+04, but the correct result is hypot = 0.000000e+00.

Keywords: kbtshoot kbprb KB891755

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.