mirror of
https://github.com/oliverbooth/X10D
synced 2024-11-10 06:15:40 +00:00
Add missing IsEven/IsOdd/Sign methods
This commit is contained in:
parent
7fb9459a91
commit
7bf8a89f82
@ -1,7 +1,4 @@
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Net;
|
||||
using System.Runtime.CompilerServices;
|
||||
using X10D.Math;
|
||||
using System.Net;
|
||||
|
||||
namespace X10D;
|
||||
|
||||
|
@ -1,6 +1,4 @@
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Net;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Net;
|
||||
using X10D.Math;
|
||||
|
||||
namespace X10D;
|
||||
@ -82,40 +80,6 @@ public static class Int32Extensions
|
||||
return BitConverter.GetBytes(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an integer that indicates the sign of this 32-bit signed integer.
|
||||
/// </summary>
|
||||
/// <param name="value">A signed number.</param>
|
||||
/// <returns>
|
||||
/// A number that indicates the sign of <paramref name="value" />, as shown in the following table.
|
||||
///
|
||||
/// <list type="table">
|
||||
/// <listheader>
|
||||
/// <term>Return value</term>
|
||||
/// <description>Meaning</description>
|
||||
/// </listheader>
|
||||
///
|
||||
/// <item>
|
||||
/// <term>-1</term>
|
||||
/// <description><paramref name="value" /> is less than zero.</description>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <term>0</term>
|
||||
/// <description><paramref name="value" /> is equal to zero.</description>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <term>1</term>
|
||||
/// <description><paramref name="value" /> is greater than zero.</description>
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// </returns>
|
||||
[Pure]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static int Sign(this int value)
|
||||
{
|
||||
return System.Math.Sign(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an enumerable collection of 32-bit signed integers that range from the current value to a specified value.
|
||||
/// </summary>
|
||||
|
@ -215,4 +215,38 @@ public static class Int32Extensions
|
||||
int r = dividend % divisor;
|
||||
return r < 0 ? r + divisor : r;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an integer that indicates the sign of this 32-bit signed integer.
|
||||
/// </summary>
|
||||
/// <param name="value">A signed number.</param>
|
||||
/// <returns>
|
||||
/// A number that indicates the sign of <paramref name="value" />, as shown in the following table.
|
||||
///
|
||||
/// <list type="table">
|
||||
/// <listheader>
|
||||
/// <term>Return value</term>
|
||||
/// <description>Meaning</description>
|
||||
/// </listheader>
|
||||
///
|
||||
/// <item>
|
||||
/// <term>-1</term>
|
||||
/// <description><paramref name="value" /> is less than zero.</description>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <term>0</term>
|
||||
/// <description><paramref name="value" /> is equal to zero.</description>
|
||||
/// </item>
|
||||
/// <item>
|
||||
/// <term>1</term>
|
||||
/// <description><paramref name="value" /> is greater than zero.</description>
|
||||
/// </item>
|
||||
/// </list>
|
||||
/// </returns>
|
||||
[Pure]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static int Sign(this int value)
|
||||
{
|
||||
return System.Math.Sign(value);
|
||||
}
|
||||
}
|
||||
|
@ -46,4 +46,34 @@ public static class UInt16Extensions
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a value indicating whether the current value is evenly divisible by 2.
|
||||
/// </summary>
|
||||
/// <param name="value">The value whose parity to check.</param>
|
||||
/// <returns>
|
||||
/// <see langword="true" /> if <paramref name="value" /> is evenly divisible by 2, or <see langword="false" />
|
||||
/// otherwise.
|
||||
/// </returns>
|
||||
[Pure]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static bool IsEven(this ushort value)
|
||||
{
|
||||
return (value & 1) == 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a value indicating whether the current value is not evenly divisible by 2.
|
||||
/// </summary>
|
||||
/// <param name="value">The value whose parity to check.</param>
|
||||
/// <returns>
|
||||
/// <see langword="true" /> if <paramref name="value" /> is not evenly divisible by 2, or <see langword="false" />
|
||||
/// otherwise.
|
||||
/// </returns>
|
||||
[Pure]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static bool IsOdd(this ushort value)
|
||||
{
|
||||
return !value.IsEven();
|
||||
}
|
||||
}
|
||||
|
@ -46,4 +46,34 @@ public static class UInt32Extensions
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a value indicating whether the current value is evenly divisible by 2.
|
||||
/// </summary>
|
||||
/// <param name="value">The value whose parity to check.</param>
|
||||
/// <returns>
|
||||
/// <see langword="true" /> if <paramref name="value" /> is evenly divisible by 2, or <see langword="false" />
|
||||
/// otherwise.
|
||||
/// </returns>
|
||||
[Pure]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static bool IsEven(this uint value)
|
||||
{
|
||||
return (value & 1) == 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a value indicating whether the current value is not evenly divisible by 2.
|
||||
/// </summary>
|
||||
/// <param name="value">The value whose parity to check.</param>
|
||||
/// <returns>
|
||||
/// <see langword="true" /> if <paramref name="value" /> is not evenly divisible by 2, or <see langword="false" />
|
||||
/// otherwise.
|
||||
/// </returns>
|
||||
[Pure]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static bool IsOdd(this uint value)
|
||||
{
|
||||
return !value.IsEven();
|
||||
}
|
||||
}
|
||||
|
@ -46,4 +46,34 @@ public static class UInt64Extensions
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a value indicating whether the current value is evenly divisible by 2.
|
||||
/// </summary>
|
||||
/// <param name="value">The value whose parity to check.</param>
|
||||
/// <returns>
|
||||
/// <see langword="true" /> if <paramref name="value" /> is evenly divisible by 2, or <see langword="false" />
|
||||
/// otherwise.
|
||||
/// </returns>
|
||||
[Pure]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static bool IsEven(this ulong value)
|
||||
{
|
||||
return (value & 1) == 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a value indicating whether the current value is not evenly divisible by 2.
|
||||
/// </summary>
|
||||
/// <param name="value">The value whose parity to check.</param>
|
||||
/// <returns>
|
||||
/// <see langword="true" /> if <paramref name="value" /> is not evenly divisible by 2, or <see langword="false" />
|
||||
/// otherwise.
|
||||
/// </returns>
|
||||
[Pure]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||
public static bool IsOdd(this ulong value)
|
||||
{
|
||||
return !value.IsEven();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user