This is the mail archive of the gcc@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]

Re: Floating point to int casts


It really blew my mind when "Tim Prince" <tprince@computer.org> said:

> 
> Since there need be no performance loss in sticking to standard
> C99, as discussed here within the last month, you should use
> lrint(), which has already a macro version in glibc
> <bits/mathinline.h>  looking much like yours.  

Wonderful. I wasn't aware of this function.

> I think Honza
> mentioned the possibility of building it into gcc rather than
> depending on the library, and I don't recall any objections.  Now
> it may be too late for gcc-3.1.

Incoporation into gcc is an even nicer option. I encourage it :-).

>   You are correct that supplying a compiler switch which has the
> effect of converting all (int) casts into lrint() and the like,
> is a bad solution, 

Yep, that is horrid.

> which is already available for a small price.
> lrint() doesn't give up accuracy; it does exactly what the
> programmer requests, exactly where it is requested.
> 
> You must be using gcc-3.0.x to see as large a performance penalty
> as you quote; the correction which Honza put into gcc-3.1 is
> unlikely to be carried back to 3.0.x.

Actually it was on both 2.95 and 3.0. I'll add tests of lrint and lrintf
and run my benchmarks again, posting the result to the list.

Erik
-- 
+-----------------------------------------------------------+
  Erik de Castro Lopo  nospam@mega-nerd.com (Yes it's valid)
+-----------------------------------------------------------+
Learning Linux is like joining a cult.  Sure it's fun at first but you waste 
time, become brainwashed, and then have to be de-programmed by Bill Gates 
before you can work for Him again.
- Ray Lopez, in UFhK4.33289$y4.1192894@newsread1.prod.itd.earthlink.net


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