CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Converting a int64 to float64 PIC24

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Jakesvanzyl



Joined: 12 Nov 2010
Posts: 5

View user's profile Send private message

Converting a int64 to float64 PIC24
PostPosted: Wed Nov 24, 2010 12:17 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Nov 24, 2010 3:02 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Nov 24, 2010 3:10 am     Reply with quote

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. Smile
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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group