[ECOS] Question for displaying floating point in eCOSaplication. Thanks a lot

sandeep sandeep@codito.com
Thu Aug 7 15:16:00 GMT 2003


> cyg_uint32 test_data = 0x40800000;
> float cov_data=0.00;
> cov_data = ((float)test_data);
this is going to represent the decimal value represented by 0x40800000 as a
floating point value. that's why you get the output as you have pasted in your
mail.

> printf("cov_data = %f, cov_data = 0x%llx\n", cov_data, cov_data);
> cov_data = 1082130432.000000, cov_data = 0x41d02000

what you seem-to-be-expecting is the floating point value represented by the
32-bit pattern 0x40800000 .

Please try following code snippet, it will help clear your confusions.

-----------------------------------------------------------
int main ()
{
  union { float f; unsigned int uui; } uvar;

  uvar.uui=0x40800000;
  printf("(float)uvar.uui=%f, uvar.f=%f\n", (float)uvar.uui, uvar.f);
  printf("uvar.uui=%x\n", uvar.uui);

  return 0;
}

you will get the output as expected now --

(float)uvar.uui=1082130432.000000, uvar.f=4.000000
uvar.uui=40800000
------------------------------------------------------------

please choose union types as (float,cyg_uint32) or
(double,cyg_uint64) and tune the program accordingly.




---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.507 / Virus Database: 304 - Release Date: 8/4/2003


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



More information about the Ecos-discuss mailing list