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

sqrt() - can i use a non-float?

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







sqrt() - can i use a non-float?
PostPosted: Tue Dec 21, 2004 8:18 am     Reply with quote

It says in the manual that sqrt() takes in a float and outputs a float. however i found that i can use non-floats, e.g. int32.

Code:

void main(void)
{
    int32 serial_number;
    int32 square_root;
   
    serial_number = 999999;   
    printf ("serial_number = %ld\r\n", serial_number);
    square_root = sqrt(serial_number);
    printf ("square root = %ld\r\n", square_root);
}


The output is:
Code:

serial_number = 999999
square root = 999


Can I thus safely use sqrt() with ints and longs and int32? Or will it be unpredictable with other numbers?

Thanks,
MIke
mvaraujo (not logged)
Guest







PostPosted: Tue Dec 21, 2004 8:51 am     Reply with quote

You can use it with any type of number.

Take care that for integers there are options for sqrt() routine that can be faster (see Code Library on the forum)!

Marcus
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