Home/Support/Support Forum/math.h functions sqrt atan, and atan2
Welcome to Digi Forum, where you can ask questions and receive answers from other members of the community.

math.h functions sqrt atan, and atan2

0 votes
Please help. I am trying to use sqrt, and atan but can only successfully compile when I pass in actual numbers instead of variables (see code below). I am wondering if it is something to do with needing to use -lm when compiling (I have seen this on a number of posts) but I don't know how or where to put it!
#include math.h void calcVelAndHdg(double northV, double eastV, double upV){ double vel2D, vel3D, hdg2D, tmp2D, tmp3D; tmp2D = pow(northV,2) + pow(eastV,2); tmp3D = pow(upV,2) + tmp2D; vel3D = sqrt(tmp3D); vel2D = sqrt(tmp2D); tmp2D = northV/eastV; hdg2D = atan(tmp2D); printf("2D velocity=%f 3D veloocity=%f 2D heading=%f \n\r", vel2D, vel3D, hdg2D); }

asked Jan 11, 2012 in NET+OS by digiDave New to the Community (20 points)
recategorized Jun 17, 2013 by mcarver

Please log in or register to answer this question.

1 Answer

0 votes
If you are using Digi ESP, then go to project properties > C/C++ Make Project > Discovery Options > Compiler invocation command arguments.

Add -lm

and try..
Let me know if this is not working.
answered Jan 12, 2012 by bobthomas13 Seasoned Professional (182 points)