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 support@ccsinfo.com

Internal Representation of Float Data Type

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



Joined: 12 Oct 2005
Posts: 7

View user's profile Send private message

Internal Representation of Float Data Type
PostPosted: Wed Oct 12, 2005 3:26 am     Reply with quote

Could someone please explain to me how float type variables are represented internally with CCS compilers?

Thanks,

Alec
Ttelmah
Guest







PostPosted: Wed Oct 12, 2005 4:50 am     Reply with quote

It's in the manual.
However just to confuse you, while the paper manual desribes the definition, the electronic version only gives the examples, without the description!....
The definition is:

Byte1 8bit exponent, with 7F bias
Bytes 2,3,4 23bit mantissa, with LSB in byte 4, and sign in the MS
bit of byte 2.

This only differs from the IEEE format, in the placement of the parts. So you can convert between the formats by just moving the sign bits around. In common with the IEEE format, the mantissa is normalised to a 24bit value with a leading '1', and then this one is dropped in storage, so there is effectively 24bit precision in the mantissa.
These routines convert to/from IEEE formats, so you should be able to look up the IEEE information, and then compare this to the CCS storage:
Code:

void toccs(int *Value) {
   //program to convert a 4 bytes 'word' from IEEE to CCS format
   int1 sign;
   sign = shift_left(&Value[1],1,0);
   sign = shift_left(&Value[0],1,sign);
   shift_right(&Value[1],1,sign);
}

void toIEEE(int *Value) {
   //complement to the above
   int1 sign;
   sign = shift_left(&Value[1], 1, 0);
   sign = shift_right(&Value[0], 1, sign);
   shift_right(&Value[1], 1, sign);
}

Calling these with a pointer to a float, changes the bit formats as required.

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