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]
Other format: [Raw text]

Re: fabs(-0.0) and soft-float


On Oct  2, 2002, Aldy Hernandez <aldyh@redhat.com> wrote:

> Should we have gcc fold fabs() like this:?

> 	 if (x > 0)
> 	   x = x;
> 	 else
> 	   x = -x;

Nope, same problem for +0.0.

I can think of two possible solutions:

  if (x < 0) x = - x;
  else if (x == 0) x = 0;

or

  if (x >= 0) x = +0.0 + x; // IIRC, +0.0 + -0.0 == +0.0
  else x = -x;

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                 aoliva@{redhat.com, gcc.gnu.org}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist                Professional serial bug killer


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