This is the mail archive of the
mailing list for the GCC project.
Re: Floating point to int casts
- To: Erik de Castro Lopo <nospam at mega-nerd dot com>
- Subject: Re: Floating point to int casts
- From: Geoff Keating <geoffk at geoffk dot org>
- Date: 18 Oct 2001 16:27:42 -0700
- CC: gcc at gcc dot gnu dot org
- References: <firstname.lastname@example.org>
Erik de Castro Lopo <email@example.com> writes:
> At the moment, the only solution to this is a rather ugly assembler macro:
> #define FLOAT_TO_INT(in,out) \
> __asm__ __volatile__ ("fistpl %0" : "=m" (out) : "t" (in) : "st") ;
> called as follows:
> float in = 1233.45 ;
> int out ;
> FLOAT_TO_INT(in, out) ;
> This macro does fix the problem but is far from an optimal solution.
You might consider using 'lrint' (or lrintf or lrintl or llrint... or
even rint) instead, which is the standard C function implemented using
this instruction. With current glibc versions, this produces code
identical to your macro.
- Geoffrey Keating <firstname.lastname@example.org>