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