AnsweredAssumed Answered

CW 6.3 SE Library Math Function Problems

Question asked by Peter Magoun on Jan 5, 2013


Disclaimer - I am a relative newbie to both CW and the C programming language - be gentle!

 

My next project will utilize an S08 target and will require small amounts of low-accuracy (32 bit) floating point math as well as a few trigonometric operations. To that end I have been experimenting with both floating point routines and trig functions in CW 6.3 SE and have encountered a few problems.

 

1. I have found that the only way to get the library math functions SQRT, SIN, COS to work at all was to declare prototype functions prior to their use. Based on my limited C knowledge, I didn't think one had to declare prototype functions when using standard library functions.  What am I doing wrong here?

 

2. While SIN and COS seem to produce the correct answers, they also seem to be overwriting numerous previously declared variables when they execute.  When I step through the functions themselves while monitoring the memory locations of the previously declared variables, things are ok until the final return statements in the trig functions are executed at which point all sorts of garbage is written into the low memory where the previously declared variables (used to) reside.  Interestingly enough, the TAN function does not seem to be guilty of this activity.  Of course, I don't need to use the TAN function.  What I am doing wrong here?

 

The "new project wizard" in CW chose all include files in the project based on my answers to its questions.  It chose ansifs.lib for the math functions. I have included the main.c file with this request.  If others are needed, let me know.

 

Any help would be GREATLY appreciated.

 

Pete

Original Attachment has been moved to: main.c.zip

Outcomes