Weird results using floating point

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

Weird results using floating point

ソリューションへジャンプ
3,158件の閲覧回数
deneb
Contributor II
Dear All
I am trying to run a couple of floating point operations and simply cannot get it working. Here is the simplest code:

float temp;
temp = 23/3.5;

After this instruction, the value of temp is 18724.582131

I am using CW 5.0.14.8093 for an HCS12NE64 microcontroller. I am using ansilf.lib.

Would anyone help me?

Thanks
-Deneb
ラベル(1)
タグ(1)
0 件の賞賛
返信
1 解決策
1,549件の閲覧回数
CrasyCat
Specialist III
Hello
 
I did some tests with CodeWarrior for HC12 V4.7.
The code is returning the appropriate result.
 
I would suggest you to create a new project using the project wizard.
Specify from the beginning you want to use 64-bit for double encoding and large memory model and then plug your code in there.
 
This should be working.
 
CrasyCat

元の投稿で解決策を見る

0 件の賞賛
返信
4 返答(返信)
1,549件の閲覧回数
kef
Specialist I
Single precision float, of value 23/3.5 = ~6.5714285, read from memory as double, with any value of the second long word, is about  18724.5 .
I don't know what happens in your case, but it could be something like project settings (double and float sizes ) are incompatible with the libraries you are using.
0 件の賞賛
返信
1,549件の閲覧回数
deneb
Contributor II
Thanks kef. I figured it out by following the information in {CodeWarrior for HCS12 V4.7\lib\hc12c\readme.txt} file. It was some settings issue, as you mentioned, for the assembler. The following settings worked with ansil.lib file.

 -D_HCS12 -Ml  -W2 -Os -F2 -NoPath

However, I still cannot get ansilf.lib to work. I need it to use IEEE64 double values. Even when I put "-Cf", it gives the wrong results, which as I understand, is swapping the higher two bytes with the lower two bytes. Is it a bug?
0 件の賞賛
返信
1,550件の閲覧回数
CrasyCat
Specialist III
Hello
 
I did some tests with CodeWarrior for HC12 V4.7.
The code is returning the appropriate result.
 
I would suggest you to create a new project using the project wizard.
Specify from the beginning you want to use 64-bit for double encoding and large memory model and then plug your code in there.
 
This should be working.
 
CrasyCat
0 件の賞賛
返信
1,549件の閲覧回数
deneb
Contributor II
Hello CrasyCat

Creating an empty project and setting appropriate options in the wizard dialogs did the trick.

Thanks to everybody


0 件の賞賛
返信