1 /* ----------------------------------------------------------------------------
\r
2 * ATMEL Microcontroller Software Support
\r
3 * ----------------------------------------------------------------------------
\r
4 * Copyright (c) 2011, Atmel Corporation
\r
6 * All rights reserved.
\r
8 * Redistribution and use in source and binary forms, with or without
\r
9 * modification, are permitted provided that the following conditions are met:
\r
11 * - Redistributions of source code must retain the above copyright notice,
\r
12 * this list of conditions and the disclaimer below.
\r
14 * Atmel's name may not be used to endorse or promote products derived from
\r
15 * this software without specific prior written permission.
\r
17 * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
\r
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
\r
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
\r
20 * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
\r
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
\r
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
\r
23 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
\r
24 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
\r
25 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
\r
26 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
27 * ----------------------------------------------------------------------------
\r
34 * \brief Compute the absolute value of the difference between two integers.
\r
35 * \param a The first integer.
\r
36 * \param b The second integer.
\r
37 * \return The absolute difference.
\r
39 #define ABS_DIFF(a,b) ((a) < (b) ? (b) - (a) : (a) - (b))
\r
41 /*------------------------------------------------------------------------------
\r
42 * Exported functions
\r
43 *------------------------------------------------------------------------------*/
\r
48 * Returns the minimum value between two integers.
\r
49 * \param a First integer to compare
\r
50 * \param b Second integer to compare
\r
52 static inline int32_t min_u32(uint32_t a, uint32_t b)
\r
54 return a < b ? a : b;
\r
58 * Returns the absolute value of an integer.
\r
59 * \param value Integer value
\r
61 static inline uint32_t abs_u32(int32_t value)
\r
63 return value > 0 ? value : -value;
\r
67 * Computes and returns x to the power of y.
\r
71 static inline uint32_t power_u32(uint32_t x, uint32_t y)
\r
73 uint32_t result = 1;
\r
81 /** ISO/IEC 14882:2003(E) - 5.6 Multiplicative operators:
\r
82 * The binary / operator yields the quotient, and the binary % operator yields the remainder
\r
83 * from the division of the first expression by the second.
\r
84 * If the second operand of / or % is zero the behavior is undefined; otherwise (a/b)*b + a%b is equal to a.
\r
85 * If both operands are nonnegative then the remainder is nonnegative;
\r
86 * if not, the sign of the remainder is implementation-defined 74).
\r
88 static inline int fixed_mod(int a, int b)
\r
97 #endif /* _INTMATH_H_ */
\r