View previous topic :: View next topic |
Author |
Message |
Jakesvanzyl
Joined: 12 Nov 2010 Posts: 5
|
Converting a int64 to float64 PIC24 |
Posted: Wed Nov 24, 2010 12:17 am |
|
|
I have successfully converted a float64 to a int64 with the following method.
step 1. Declare a Union
Code: |
union {
int8 b[8];
float64 f;
} floatConversion;
|
step 2. set the float64 value in the main code
Code: |
floatConversion.f = 3.2;
|
step 3. Get the 8 bytes from floatConversion.b
I have checked the values are in the correct IEEE standard and it works well
The problem I have is I want to convert the int64 back to float64 I have tried the above code in reverse but it does not work.
Can somebody please help me with this problem?
PIC = 24FJ48GA002 |
|
|
Wayne_
Joined: 10 Oct 2007 Posts: 681
|
|
Posted: Wed Nov 24, 2010 3:02 am |
|
|
Microchip do not follow IEEE standard for float32s, the sign bit is in a different place, I assume the same applies to float64s but can not be certain. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19543
|
|
Posted: Wed Nov 24, 2010 3:10 am |
|
|
On PCD, the floats are IEEE standard.
This is why the code in IEEEfloat.c, tests the compiler, and returns 'invalid' for PCD.
What is posted, should work 'both ways'. Not converting to an int64, but to 8*int8's though.
Obvious thing really would be something wrong with the byte order into the array etc., when writing back.
Really need to use a debugger, and see if the values in the 8byte array are what is expected. If not in a debugging environment, then RS232, and print the bytes out.
Best Wishes |
|
|
|