Why does my MEX-file compile correctly but produces incorrect results when I call C math functions without including "math.h"?

3 views (last 30 days)
I create a C-file that uses a C math function, but do not include "math.h". Next, I use MATLAB 7.0 (R14) to create a MEX-file using:
mex myfile.c
The MEX function does not produce any errors or warnings, but when I call the MEX-file from MATLAB, I obtain incorrect results. For example, if I use the "sin" function, my results ia always 32.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
We have verified that there is a bug in MATLAB 7.0 (R14) in the way that the MEX function handles compiling code that uses C math functions when the appropriate header is not included.
To work around this issue, be sure to include the required header file, which in this case is "math.h", in your C file before creating a MEX-file.

More Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!