namespace PMaker.Extension
{
public static class IntExtension
{
///
/// 判断是否在指定范围内
///
///
/// 最小值
/// 最大值
///
public static bool IsClamp(this int value, int min, int max)
{
return value <= max & value >= min;
}
///
/// 某一范围内循环自增
///
///
///
///
public static void CyclicAdd(ref this int value, int max, int min = 0)
{
value = (value - min + 1) % max + min;
}
///
/// 某一范围内循环自减
///
///
///
///
public static void CyclicSub(ref this int value, int max, int min = 0)
{
value = (value - min + max - 1) % max + min;
}
//public static int CyclicAdd(this int value, int max, int min = 0)
//{
// return (value - min + 1) % max + min;
//}
//public static int CyclicSub(this int value, int max, int min = 0)
//{
// return (value - min + max - 1) % max + min;
//}
///
/// 设置指定bit位为1
///
///
/// 0base
public static void BitOn(ref this int value, int index)
{
value |= (1 << index);
}
///
/// 设置指定bit位为0
///
///
/// 0base
public static void BitOff(ref this int value, int index)
{
value &= ~(1 << index);
}
///
/// 判断是否包含目标值
///
///
///
///
public static bool BitIs(this int value, int target)
{
return (value & target) == target;
}
}
}