This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC 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: Soft float support and casting


At Wed, 29 Nov 2006 04:43:06 -0800,
Michael Eager wrote:
> 
> 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;
> }

Ah, of course - less magic than I was expecting. :-)

Thanks,
// Simon


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]