Weird results using floating point

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

Weird results using floating point

Jump to solution
2,210 Views
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
Labels (1)
Tags (1)
0 Kudos
1 Solution
601 Views
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

View solution in original post

0 Kudos
4 Replies
601 Views
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 Kudos
601 Views
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 Kudos
602 Views
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 Kudos
601 Views
deneb
Contributor II
Hello CrasyCat

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

Thanks to everybody


0 Kudos