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


Hi:

Another more comprehensive try:

double test_double=4.00;
float test_float=4.00;
cyg_uint32 test_data = 0x40800000;
float cov_data=0.00;
cov_data = ((float)test_data);
printf("test_double = %f, test_float = %f\n", test_double, test_float);
printf("test_double=0x%llx, test_float=0x%llx\n", test_double, test_float);
printf("test_data = %f, test_data = 0x%llx\n", (float)test_data, test_data);
printf("cov_data = %f, cov_data = 0x%llx\n", cov_data, cov_data);

// Output as:
test_double = 4.000000, test_float = 4.000000
test_double=0x40100000, test_float=0x40100000
test_data = 1082130432.000000, test_data = 0x40800000
cov_data = 1082130432.000000, cov_data = 0x41d02000

seems no matter I set the variable to either float or double they are using
the same format as real*8, is this the case?


BTW any format flag to indicate the data to be printfed is real*4 (float) or
real*8 (double) ? Thanks a lot.

qiang

-----Original Message-----
From: ecos-discuss-owner@sources.redhat.com
[mailto:ecos-discuss-owner@sources.redhat.com]On Behalf Of Andrew Lunn
Sent: 07 August 2003 14:30
To: QiangHuang
Cc: Ecos-Discuss
Subject: Re: [ECOS] 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
>
> Did I make anything wrong here?
> can anybody help on this? Thanks a lot.

Approaching the problem from the other end:

int main(int argc, char * argv[])
{
  float f = 4.0;
  double d = 4.0;

  printf("f=%f, 0x%x\n",f,*(unsigned long *)&f);
  printf("d=%f, 0x%llx\n",f,*(unsigned long long *)&d);

  return 0;
}

./float
f=4.000000, 0x40800000
d=4.000000, 0x4010000000000000

I was talking nonsense about normalization. I should go back and read
the CompSci text book.

You problems might be types and casting. Notice how i cast my
float/double before printing them. If your real8_data truly is a
cyg_uint32, the compiler will silently convert it to a double before
printing it. Although i would not expect 512!

         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


-- 
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]