2 * The copyright in this software is being made available under the 2-clauses
3 * BSD License, included below. This software may be subject to other third
4 * party and contributor rights, including patent rights, and no such rights
5 * are granted under this license.
7 * Copyright (c) 2001-2003, David Janssens
8 * Copyright (c) 2002-2003, Yannick Verschueren
9 * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe
10 * Copyright (c) 2005, Herve Drolon, FreeImage Team
11 * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium
12 * All rights reserved.
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
39 @brief Implementation of operations on integers (INT)
41 The functions in INT.H have for goal to realize operations on integers.
44 /** @defgroup INT INT - Implementation of operations on integers */
47 /** @name Funciones generales (see also openjp3d.h) */
49 /* ----------------------------------------------------------------------- */
51 Get the minimum of two integers
52 @return Returns a if a < b else b
54 static int int_min(int a, int b) {
58 Get the maximum of two integers
59 @return Returns a if a > b else b
61 static int int_max(int a, int b) {
62 return (a > b) ? a : b;
65 Clamp an integer inside an interval
68 <li>Returns a if (min < a < max)
69 <li>Returns max if (a > max)
70 <li>Returns min if (a < min)
73 static int int_clamp(int a, int min, int max) {
81 @return Get absolute value of integer
83 static int int_abs(int a) {
84 return a < 0 ? -a : a;
87 static double dbl_abs(double a) {
88 return a < 0 ? -a : a;
91 Divide an integer and round upwards
92 @return Returns a divided by b
94 static int int_ceildiv(int a, int b) {
95 return (a + b - 1) / b;
98 Divide an integer by a power of 2 and round upwards
99 @return Returns a divided by 2^b
101 static int int_ceildivpow2(int a, int b) {
102 return (a + (1 << b) - 1) >> b;
105 Divide an integer by a power of 2 and round downwards
106 @return Returns a divided by 2^b
108 static int int_floordivpow2(int a, int b) {
112 Get logarithm of an integer and round downwards
113 @return Returns log2(a)
115 static int int_floorlog2(int a) {
117 for (l = 0; a > 1; l++) {
122 /* ----------------------------------------------------------------------- */