1 | /* GTK - The GIMP Toolkit |
2 | * Copyright (C) 2011 Chun-wei Fan <fanc999@yahoo.com.tw> |
3 | * |
4 | * Author: Chun-wei Fan <fanc999@yahoo.com.tw> |
5 | * |
6 | * This library is free software; you can redistribute it and/or |
7 | * modify it under the terms of the GNU Lesser General Public |
8 | * License as published by the Free Software Foundation; either |
9 | * version 2 of the License, or (at your option) any later version. |
10 | * |
11 | * This library is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | * Lesser General Public License for more details. |
15 | * |
16 | * You should have received a copy of the GNU Lesser General Public |
17 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. |
18 | */ |
19 | |
20 | #include <math.h> |
21 | |
22 | /* Workaround for round() for non-GCC/non-C99 compilers */ |
23 | #ifndef HAVE_ROUND |
24 | static inline double |
25 | round (double x) |
26 | { |
27 | if (x >= 0) |
28 | return floor (x + 0.5); |
29 | else |
30 | return ceil (x - 0.5); |
31 | } |
32 | #endif |
33 | |
34 | /* Workaround for lrint() for non-GCC/non-C99 compilers */ |
35 | #ifndef HAVE_LRINT |
36 | static inline long |
37 | lrint (double x) |
38 | { |
39 | if (ceil (x + 0.5) == floor (x + 0.5)) |
40 | { |
41 | if (x < 1 && x > -1) |
42 | return 0; |
43 | |
44 | return (int) ceil (x) % 2 == 0 ? ceil (x) : floor (x); |
45 | } |
46 | else |
47 | return x >= 0 ? floor (x + 0.5) : ceil (x - 0.5); |
48 | } |
49 | #endif |