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

Negative result for POW function

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



Joined: 10 Feb 2004
Posts: 205

View user's profile Send private message

Negative result for POW function
PostPosted: Wed Oct 01, 2008 12:42 pm     Reply with quote

I looked through the math.h file and found in 3.249 that the POW function returns a negative number when squaring the value.

Code:

temp = -2;
temp1 = pow(temp,2);

temp1 = -4


from math.h
Code:


float pow(float x,float y)
{
   if(x>=0)
     return(  exp(y*log(x)) );
   else
     return(  -exp(y*log(-x)) );
}

PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Oct 01, 2008 4:10 pm     Reply with quote

Here are some replacements for the CCS pow() function, with source code:
https://www.ccsinfo.com/forum/viewtopic.php?p=2710
http://www.mindspring.com/~pfilandr/C/fs_math/fs_math.c
https://www.ccsinfo.com/forum/viewtopic.php?t=30183
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