sqrtf() mathematical function not yielding correct answer!!!

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

sqrtf() mathematical function not yielding correct answer!!!

673 Views
bingo23
Contributor I

Hello,

Im using CW 6.3 for programming Coldfire V1 MCF51EM256.

The problem that im facing is that the sqrtf() function for square root is giving incorrect answer. I've included the required header file "math.h". When compiling it does'nt give me any errors or warnings as well; just the value returned by the function is wrong!!!

Please advice if there is anything else i need to do to use mathematical functions other than including "math.h".

Thanks in advance!!!

Labels (1)
0 Kudos
3 Replies

359 Views
CrasyCat
Specialist III

Hello

 

You need to link the appropriate MSL library to your project.

 

Please create a new project using the wizard in codeWarrior and specify you are going to use floating point arithmetic.

The project should be correctly set up to enable usage of math functions.

 

CrasyCat

0 Kudos

359 Views
bingo23
Contributor I

Thanks for the reply. However  I have a doubt.

When creating a new project the only option i get regarding enabling floating point arithmetic is "Select if you want floating point support" with two selection settings: 1.None  2. float is IEEE64,double is IEEE64 .

My doubt is if i select the 2nd setting, won't my float also become 64 bits i.e. 8 bytes?? If this is the case then I wont be able to use it because of a space constraint!!!

0 Kudos

359 Views
CrasyCat
Specialist III

Hello

 

I did a quick test with v10.1 and Coldfire v1 project.

  

     sizeof(float)      returns 4

     sizeof(double) returns 8.

 

So according to my understanding float variables are stored on 4 bytes.

 

Note that if you enable c99 language you should be able to use fiction sqrtf, which is an implementation of sqrt with float parameter and return value  instead of double.

If you activate c99 language you need to link the appropriate library to your project.

 

For library naming convention check MCU_ColdFire_Compiler.pdf, chapter ColdFire runtime Libraries.

 

CrasyCat

0 Kudos