Blame gdk-pixbuf/fallback-c89.c

Packit a4058c
/* GTK - The GIMP Toolkit
Packit a4058c
 * Copyright (C) 2011 Chun-wei Fan <fanc999@yahoo.com.tw>
Packit a4058c
 *
Packit a4058c
 * Author: Chun-wei Fan <fanc999@yahoo.com.tw>
Packit a4058c
 *
Packit a4058c
 * This library is free software; you can redistribute it and/or
Packit a4058c
 * modify it under the terms of the GNU Lesser General Public
Packit a4058c
 * License as published by the Free Software Foundation; either
Packit a4058c
 * version 2 of the License, or (at your option) any later version.
Packit a4058c
 *
Packit a4058c
 * This library is distributed in the hope that it will be useful,
Packit a4058c
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit a4058c
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit a4058c
 * Lesser General Public License for more details.
Packit a4058c
 *
Packit a4058c
 * You should have received a copy of the GNU Lesser General Public
Packit a4058c
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
Packit a4058c
 */
Packit a4058c
Packit a4058c
#include <math.h>
Packit a4058c
 
Packit a4058c
/* Workaround for round() for non-GCC/non-C99 compilers */
Packit a4058c
#ifndef HAVE_ROUND
Packit a4058c
static inline double
Packit a4058c
round (double x)
Packit a4058c
{
Packit a4058c
  if (x >= 0)
Packit a4058c
    return floor (x + 0.5);
Packit a4058c
  else
Packit a4058c
    return ceil (x - 0.5);
Packit a4058c
}
Packit a4058c
#endif
Packit a4058c
Packit a4058c
/* Workaround for lrint() for non-GCC/non-C99 compilers */
Packit a4058c
#ifndef HAVE_LRINT
Packit a4058c
static inline long
Packit a4058c
lrint (double x)
Packit a4058c
{
Packit a4058c
  if (ceil (x + 0.5) == floor (x + 0.5))
Packit a4058c
    {
Packit a4058c
      if (x < 1 && x > -1)
Packit a4058c
        return 0;
Packit a4058c
Packit a4058c
      return (int) ceil (x) % 2 == 0 ? ceil (x) : floor (x);
Packit a4058c
    }
Packit a4058c
  else
Packit a4058c
    return x >= 0 ? floor (x + 0.5) : ceil (x - 0.5);
Packit a4058c
}
Packit a4058c
#endif