Soft float support and casting

Michael Eager eager@eagercon.com
Wed Nov 29 12:43:00 GMT 2006


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@eagercon.com
1960 Park Blvd., Palo Alto, CA 94306  650-325-8077



More information about the Gcc-help mailing list