This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
Re: Question for displaying floating point in eCOSaplication. Thanks a lot
- From: "sandeep" <sandeep at codito dot com>
- To: "QiangHuang" <jameshq at liverpool dot ac dot uk>
- Cc: "Ecos-Discuss" <ecos-discuss at sources dot redhat dot com>
- Date: Thu, 7 Aug 2003 20:56:51 +0530
- Subject: Re: [ECOS] Question for displaying floating point in eCOSaplication. Thanks a lot
- References: <ONEOIJPPOKNBBKJKCGLCKEEMCCAA.jameshq@liv.ac.uk>
> 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