CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

problem with math.h lib ???

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
elmar44



Joined: 07 Jun 2005
Posts: 1

View user's profile Send private message

problem with math.h lib ???
PostPosted: Fri Jun 17, 2005 4:41 am     Reply with quote

Hi to all programmers..
Now i used the math.h lib first time to get access to functions like
sin() , pow(x,y) ....
So i start with a sinple check:

#include math.h
float x, result;
x = 45
result = sin(x); // the result = 0.707!
..(break)
I used the debugger to watch 'result' and the displayed result is: "1"
sin(45°) = 1 ????
OK - changed the line to result = tan(45);
The displayed result is "0"....... tan(45°) = 0 ?????
So i try another function:
float x, y, result
x = 10;
y = 3;
result = pow(x,y); // this means 10^3 = 1000 !
the displayed result is : -1.345E-24 or results like this - not a "1000"

SO: HOW CAN I USE THE MATH.H LIB ???
What's wrong ????

Thank you for help
valemike
Guest







PostPosted: Fri Jun 17, 2005 6:35 am     Reply with quote

Which debugger are you using? My past experience has shown that the MPLAB IDE debugger does not interpret CCS's floats properly. A printf ("%f", floar_var); of your value to Hyperterminal ought to give you the correct results though.

-Mike
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jun 17, 2005 10:19 am     Reply with quote

Quote:
#include math.h
float x, result;
x = 45
result = sin(x); // the result = 0.707!
..(break)
I used the debugger to watch 'result' and the displayed result is: "1"
sin(45°) = 1 ????

The reason is because the math.h library uses Radians, not degrees.
This is stated in the CCS manual, in the section on Sin().
Do it like this to get the correct answer:
Code:
result = sin(PI/2);


Quote:
result = pow(x,y); // this means 10^3 = 1000 !
the displayed result is : -1.345E-24 or results like this - not a "1000"

This worked OK for me with PCM vs. 3.225 and MPLAB vs. 7.10.
I have the format of the "result" variable set for MCHP floating point
(not Scientific). This is done in the Properties box for "result" in the
Watch window.

Before we go any farther on this, please post your version of the
CCS compiler and of MPLAB.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group