Re: Soft float support and casting

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Simon Kagstrom wrote:

I've looked in libgcc2.c and am unfortunately a bit unsure about how
to get GCC to directly cast an integer value to a float type. For
example, I would like to do something like this:

   float __floatsisf(long i)
   {
       return (float)0x40c00000; /* float value 6.0 */
   }

but the cast will of course turn this into some completely different
number. Can someone quickly explain how to do this?

Use a union:

union { float f; unsigned int i; } u;

float __floatsisf(long i)
{
   u.i = 0x40c00000;
   return u.f;
}


--
Michael Eager	 eager@xxxxxxxxxxxx
1960 Park Blvd., Palo Alto, CA 94306  650-325-8077

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux