Weird results using floating point

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Weird results using floating point

跳至解决方案
3,102 次查看
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,493 次查看
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,493 次查看
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,493 次查看
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,494 次查看
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,493 次查看
deneb
Contributor II
Hello CrasyCat

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

Thanks to everybody


0 项奖励
回复