using float with CW3

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

using float with CW3

2,042件の閲覧回数
khumphri
NXP Employee
NXP Employee

This message contains an entire topic ported from a separate forum. The original message and all replies are in this single message. We have seeded this new forum with selected information that we expect will be of value to you as you search for answers to your questions.

 

Posted: Thu Jun 16, 2005  9:49 am

 

Hello

 

I do this in a function

 

float toto;

toto=2.34;

 

When i debug it toto is always 2!!!

 

I don't understand why. I have no error at the compilation.

 

Thank you very much for help

 


 

Posted: Thu Jun 16, 2005  9:56 am

 

You must put "F" in the end.

 

toto=2.34F;

 

 

Posted: Thu Jun 16, 2005  2:28 pm

 

I just added this global:

float GLOB=2.14;

 

(gdb) p GLOB

$1 = 2.1400001

 

So as per C standard, you do not need 'F' at the end. The '.' indicates float. I guess it must have been something with P&E debugger. I guess my gdb uses more information from debug information to know the variable is a float.

 


 

Posted: Thu Jun 16, 2005  5:02 pm

 

For the ANSI-C standard, you do need the F, otherwise its a double, not a float.

 

For your case of just initializing a variable, the difference is optimized away as the compiler will do the conversion at compile time. However if you start to use 2.14 as part of a computation and you configured the compiler to support IEEE64 doubles, then you will get a more code when using 2.14 than with 2.14F.

 


 

Posted: Thu Jun 16, 2005  9:59 am

 

It doesn't work :smileysad:

 


 

Posted: Thu Jun 16, 2005  10:15 am

 

Perhaps this is the debugger?

 

I use P&E product. Is there is something to do for float operations?

 


 

Posted: Thu Jun 16, 2005  11:58 am

 

Ok I find the solution.

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