This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Question for displaying floating point in eCOS aplication. Thanks a lot


On Thu, Aug 07, 2003 at 01:43:58PM +0100, QiangHuang wrote:
> Hi all:
>    I tried to use fprintf() to display a floating point value but seems it
> is real*8 format. is this right? my data is in real*4 format so what flag
> should I use to display floating point (real*4 format) data with fprintf()?
> 
> for example
> 
> 
> // data in real*8 format = 4
> cyg_uint32 real8_data = 0x4010 0000;
> 
> // data in real*4 format = 4
> cyg_uint32 real4_data = 0x4080 0000;
> 
> fprintf(client, "%f ", real8_data);
> // I can see the output is: 4 -- correct
> 
> fprintf(client, "%f ", real4_data);
> // I can see the output is:  512 -- not correct

After a quick bit of googling.

real*4 is a float in C and takes 4 bytes.
real*8 is a double in C and take 8 bytes. 

So your real8_data is wrong, it should be a cyg_uint64.

Also, your initializations are wrong, well strange may be more
accurate. You have not normalized them. 

Take a look at 

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcce/htm/evc_guide10_30.asp

Or any good computer science text book.

   Andrew

-- 
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]