This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
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