Changeset - r7827:c754de5e3818
[Not reviewed]
master
0 1 0
truelight - 17 years ago 2007-11-04 17:43:53
truelight@openttd.org
(svn r11377) -Codechange: some more strictness in macros.h (skidd13)
1 file changed with 8 insertions and 10 deletions:
0 comments (0 inline, 0 general)
src/macros.h
Show inline comments
 
@@ -104,14 +104,13 @@ template<typename T> static inline T min
 
 * @param a The first integer
 
 * @param b The second integer
 
 * @return The smaller value
 
 */
 
static inline int min(const int a, const int b)
 
{
 
	if (a <= b) return a;
 
	return b;
 
	return a <= b ? a : b;
 
}
 

	
 
/**
 
 * Returns the minimum of two unsigned integers.
 
 *
 
 * This function returns the smaller value of two given unsigned integers.
 
@@ -119,14 +118,13 @@ static inline int min(const int a, const
 
 * @param a The first unsigned integer
 
 * @param b The second unsigned integer
 
 * @return The smaller value
 
 */
 
static inline uint minu(const uint a, const uint b)
 
{
 
	if (a <= b) return a;
 
	return b;
 
	return a <= b ? a : b;
 
}
 

	
 
/**
 
 * Clamp an integer between an interval.
 
 *
 
 * This function returns a value which is between the given interval of
 
@@ -201,13 +199,13 @@ static inline int32 ClampToI32(const int
 
 *
 
 * @param a The first integer
 
 * @param b The second integer
 
 * @param shift The amount to shift the value to right.
 
 * @return The shifted result
 
 */
 
static inline int32 BIGMULSS(const int32 a, const int32 b, const int8 shift)
 
static inline int32 BIGMULSS(const int32 a, const int32 b, const uint8 shift)
 
{
 
	return (int32)((int64)a * (int64)b >> shift);
 
}
 

	
 
/**
 
 * Multiply two unsigned integers and shift the results to right.
 
@@ -217,13 +215,13 @@ static inline int32 BIGMULSS(const int32
 
 *
 
 * @param a The first unsigned integer
 
 * @param b The second unsigned integer
 
 * @param shift The amount to shift the value to right.
 
 * @return The shifted result
 
 */
 
static inline uint32 BIGMULUS(const uint32 a, const uint32 b, const int8 shift)
 
static inline uint32 BIGMULUS(const uint32 a, const uint32 b, const uint8 shift)
 
{
 
	return (uint32)((uint64)a * (uint64)b >> shift);
 
}
 

	
 

	
 
/**
 
@@ -250,13 +248,13 @@ static inline uint32 BIGMULUS(const uint
 
 * LSB and count from 0.
 
 *
 
 * @param x The value to check
 
 * @param y The position of the bit to check, started from the LSB
 
 * @return True if the bit is set, false else.
 
 */
 
template<typename T> static inline bool HASBIT(const T x, const int8 y)
 
template<typename T> static inline bool HASBIT(const T x, const uint8 y)
 
{
 
	return (x & ((T)1U << y)) != 0;
 
}
 

	
 
/**
 
 * Set a bit in a variable.
 
@@ -266,13 +264,13 @@ template<typename T> static inline bool 
 
 * starts at the LSB with 0.
 
 *
 
 * @param x The variable to set a bit
 
 * @param y The bit position to set
 
 * @return The new value of the old value with the bit set
 
 */
 
template<typename T> static inline T SETBIT(T& x, const int8 y)
 
template<typename T> static inline T SETBIT(T& x, const uint8 y)
 
{
 
	return x |= (T)1U << y;
 
}
 

	
 
/**
 
 * Clears a bit in a variable.
 
@@ -282,13 +280,13 @@ template<typename T> static inline T SET
 
 * to clear and starts at the LSB with 0.
 
 *
 
 * @param x The variable to clear the bit
 
 * @param y The bit position to clear
 
 * @return The new value of the old value with the bit cleared
 
 */
 
template<typename T> static inline T CLRBIT(T& x, const int8 y)
 
template<typename T> static inline T CLRBIT(T& x, const uint8 y)
 
{
 
	return x &= ~((T)1U << y);
 
}
 

	
 
/**
 
 * Toggles a bit in a variable.
 
@@ -298,13 +296,13 @@ template<typename T> static inline T CLR
 
 * to toggle and starts at the LSB with 0.
 
 *
 
 * @param x The varliable to toggle the bit
 
 * @param y The bit position to toggle
 
 * @return The new value of the old value with the bit toggled
 
 */
 
template<typename T> static inline T TOGGLEBIT(T& x, const int8 y)
 
template<typename T> static inline T TOGGLEBIT(T& x, const uint8 y)
 
{
 
	return x ^= (T)1U << y;
 
}
 

	
 

	
 
/* checking more bits. Maybe unneccessary, but easy to use */
0 comments (0 inline, 0 general)