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

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

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

969件の閲覧回数
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!!!

ラベル(1)
0 件の賞賛
返信
3 返答(返信)

655件の閲覧回数
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 件の賞賛
返信

655件の閲覧回数
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 件の賞賛
返信

655件の閲覧回数
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 件の賞賛
返信