This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

tan math.h does not work

Hi, I am using Windows 7 (Service Pack 1) , Code Compressor Studio 5.5.0 and Board TMS320C6713 DSK. 

Currently I am writing .c (shown as below)

My main.c has interrupt which will call this .c and I found out I have problem with <math.h> (I assume)

I would like to calculate a_b by using tan() math function. But it keeps showing the output is 0.

Is it due to library ? 

Am I missing something important? 

  • You can download and use MATH library for C6713 device.
    software-dl.ti.com/.../index_FDS.html
  • Hi,

    Thanks for your post.

    Are you using C++ code? If C++ code, math.h is deprecated and you couldn't use CGT compiler built in library routines belong to "math.h"

    If C, I don't think, it should be problem with math.h std. library routines, it might be with the program logic and nothing else, You could set breakpoints and step through the code, you would be able to fix the issue.

    One more, did you include the compiler library search path "~\ccsv5\tools\compiler\c6000_7.4.4\lib\libc.a in the file search path of project properties, kindly check on this since libc.a A file, which include all rts library files for both ELF and COFF file formats.

    Next, I checked the CGT compiler include file "math.h" and checked the "tan" subroutine prototype as below which takes double data type variable x and returns double  which is part of extern "C" namespace std and shown the include file path below for your reference:

    ~\ccsv5\tools\compiler\c6000_7.4.4\include\math.h

    With reference to above file, I see your above code and would like to clarify the following:

    a_b=tan(fb/fs);

    in the above statement, fb is fc/Q which is a short int data type and fs is float data type. I think, this would be contradictory with the function prototype declared in the "tan" subroutine of math.h which is showed below for your reference:

    __EXTERN double tan  (double x); ( This snippet is from ~\ccsv5\tools\compiler\c6000_7.4.4\include\math.h)

    Why don't you try type cast your variable fb to double and fs to double and also ensure the return value of tan(fb/fs)  which is stored in a_b variable should comply with double datatype?  Kindly validate this.

    In my understanding, we shouldn't see any issues with compiler std. built in math library routines such as sin, cos, tan etc.

    Thanks & regards,

    Sivaraj K

    -------------------------------------------------------------------------------------------------------

    Please click the Verify Answer button on this post if it answers your question.

    -------------------------------------------------------------------------------------------------------

  • Adding to what Sivaraj correctly said

    Other calculations are wrong if the variables are int.  For example g/20 (if g is integer) is zero.  This is what you want?  If you want 0.5  (g=10) then define the arguments as float or better, double

    Ran

  • Thank you for the advice. Now it works!