mirror of
https://github.com/oliverbooth/X10D
synced 2024-11-10 03:45:41 +00:00
✨ Add IsEven and IsOdd for integral types
This commit is contained in:
parent
9844bccd28
commit
b2455d1bcd
@ -45,6 +45,28 @@
|
|||||||
return BitConverter.GetBytes(number);
|
return BitConverter.GetBytes(number);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Determines if the <see cref="Double"/> is even.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="number">The number.</param>
|
||||||
|
/// <returns>Returns <see langword="true"/> if <paramref name="number"/> is even, <see langword="false"/>
|
||||||
|
/// otherwise.</returns>
|
||||||
|
public static bool IsEven(this double number)
|
||||||
|
{
|
||||||
|
return Math.Abs(number % 2.0) < Double.Epsilon;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Determines if the <see cref="Double"/> is odd.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="number">The number.</param>
|
||||||
|
/// <returns>Returns <see langword="true"/> if <paramref name="number"/> is odd, <see langword="false"/>
|
||||||
|
/// otherwise.</returns>
|
||||||
|
public static bool IsOdd(this double number)
|
||||||
|
{
|
||||||
|
return !number.IsEven();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Converts an angle from radians to degrees.
|
/// Converts an angle from radians to degrees.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -138,6 +138,50 @@
|
|||||||
return BitConverter.GetBytes(number);
|
return BitConverter.GetBytes(number);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Determines if the <see cref="Int16"/> is even.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="number">The number.</param>
|
||||||
|
/// <returns>Returns <see langword="true"/> if <paramref name="number"/> is even, <see langword="false"/>
|
||||||
|
/// otherwise.</returns>
|
||||||
|
public static bool IsEven(this short number)
|
||||||
|
{
|
||||||
|
return ((long) number).IsEven();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Determines if the <see cref="UInt16"/> is even.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="number">The number.</param>
|
||||||
|
/// <returns>Returns <see langword="true"/> if <paramref name="number"/> is even, <see langword="false"/>
|
||||||
|
/// otherwise.</returns>
|
||||||
|
public static bool IsEven(this ushort number)
|
||||||
|
{
|
||||||
|
return ((ulong) number).IsEven();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Determines if the <see cref="Int16"/> is odd.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="number">The number.</param>
|
||||||
|
/// <returns>Returns <see langword="true"/> if <paramref name="number"/> is odd, <see langword="false"/>
|
||||||
|
/// otherwise.</returns>
|
||||||
|
public static bool IsOdd(this short number)
|
||||||
|
{
|
||||||
|
return !number.IsEven();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Determines if the <see cref="UInt16"/> is odd.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="number">The number.</param>
|
||||||
|
/// <returns>Returns <see langword="true"/> if <paramref name="number"/> is odd, <see langword="false"/>
|
||||||
|
/// otherwise.</returns>
|
||||||
|
public static bool IsOdd(this ushort number)
|
||||||
|
{
|
||||||
|
return !number.IsEven();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Determines if the <see cref="Int16"/> is a prime number.
|
/// Determines if the <see cref="Int16"/> is a prime number.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -149,6 +193,17 @@
|
|||||||
return ((long) number).IsPrime();
|
return ((long) number).IsPrime();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Determines if the <see cref="Int16"/> is a prime number.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="number">The number.</param>
|
||||||
|
/// <returns>Returns <see langword="true"/> if <paramref name="number"/> is prime, <see langword="false"/>
|
||||||
|
/// otherwise.</returns>
|
||||||
|
public static bool IsPrime(this ushort number)
|
||||||
|
{
|
||||||
|
return ((ulong) number).IsPrime();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets an boolean value that represents this integer.
|
/// Gets an boolean value that represents this integer.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -298,6 +298,50 @@
|
|||||||
return BitConverter.GetBytes(number);
|
return BitConverter.GetBytes(number);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Determines if the <see cref="Int32"/> is even.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="number">The number.</param>
|
||||||
|
/// <returns>Returns <see langword="true"/> if <paramref name="number"/> is even, <see langword="false"/>
|
||||||
|
/// otherwise.</returns>
|
||||||
|
public static bool IsEven(this int number)
|
||||||
|
{
|
||||||
|
return ((long)number).IsEven();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Determines if the <see cref="UInt32"/> is even.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="number">The number.</param>
|
||||||
|
/// <returns>Returns <see langword="true"/> if <paramref name="number"/> is even, <see langword="false"/>
|
||||||
|
/// otherwise.</returns>
|
||||||
|
public static bool IsEven(this uint number)
|
||||||
|
{
|
||||||
|
return ((ulong)number).IsEven();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Determines if the <see cref="Int32"/> is odd.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="number">The number.</param>
|
||||||
|
/// <returns>Returns <see langword="true"/> if <paramref name="number"/> is odd, <see langword="false"/>
|
||||||
|
/// otherwise.</returns>
|
||||||
|
public static bool IsOdd(this int number)
|
||||||
|
{
|
||||||
|
return !number.IsEven();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Determines if the <see cref="UInt32"/> is odd.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="number">The number.</param>
|
||||||
|
/// <returns>Returns <see langword="true"/> if <paramref name="number"/> is odd, <see langword="false"/>
|
||||||
|
/// otherwise.</returns>
|
||||||
|
public static bool IsOdd(this uint number)
|
||||||
|
{
|
||||||
|
return !number.IsEven();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Determines if the <see cref="Int32"/> is a prime number.
|
/// Determines if the <see cref="Int32"/> is a prime number.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -137,6 +137,50 @@
|
|||||||
return BitConverter.GetBytes(number);
|
return BitConverter.GetBytes(number);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Determines if the <see cref="Int64"/> is even.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="number">The number.</param>
|
||||||
|
/// <returns>Returns <see langword="true"/> if <paramref name="number"/> is even, <see langword="false"/>
|
||||||
|
/// otherwise.</returns>
|
||||||
|
public static bool IsEven(this long number)
|
||||||
|
{
|
||||||
|
return Math.Abs(number % 2.0) < Double.Epsilon;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Determines if the <see cref="UInt64"/> is even.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="number">The number.</param>
|
||||||
|
/// <returns>Returns <see langword="true"/> if <paramref name="number"/> is even, <see langword="false"/>
|
||||||
|
/// otherwise.</returns>
|
||||||
|
public static bool IsEven(this ulong number)
|
||||||
|
{
|
||||||
|
return Math.Abs(number % 2.0) < Double.Epsilon;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Determines if the <see cref="Int64"/> is odd.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="number">The number.</param>
|
||||||
|
/// <returns>Returns <see langword="true"/> if <paramref name="number"/> is odd, <see langword="false"/>
|
||||||
|
/// otherwise.</returns>
|
||||||
|
public static bool IsOdd(this long number)
|
||||||
|
{
|
||||||
|
return !IsEven(number);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Determines if the <see cref="UInt64"/> is odd.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="number">The number.</param>
|
||||||
|
/// <returns>Returns <see langword="true"/> if <paramref name="number"/> is odd, <see langword="false"/>
|
||||||
|
/// otherwise.</returns>
|
||||||
|
public static bool IsOdd(this ulong number)
|
||||||
|
{
|
||||||
|
return !IsEven(number);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Determines if the <see cref="Int64"/> is a prime number.
|
/// Determines if the <see cref="Int64"/> is a prime number.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -15,12 +15,12 @@ Below is a list of the number of extension methods written for a given type. Ove
|
|||||||
| `IConvertible` | `X10D` | 4 |
|
| `IConvertible` | `X10D` | 4 |
|
||||||
| `DateTime` | `X10D` | 11 |
|
| `DateTime` | `X10D` | 11 |
|
||||||
| `EndPoint` | `X10D` | 2 |
|
| `EndPoint` | `X10D` | 2 |
|
||||||
| `double` | `X10D` | 5 |
|
| `double` | `X10D` | 7 |
|
||||||
| `enum` | `X10D` | 2 |
|
| `enum` | `X10D` | 2 |
|
||||||
| `float` | `X10D` | 5 |
|
| `float` | `X10D` | 7 |
|
||||||
| `short` / `ushort` | `X10D` | 11 |
|
| `short` / `ushort` | `X10D` | 11 |
|
||||||
| `int` / `uint` | `X10D` | 23 |
|
| `int` / `uint` | `X10D` | 25 |
|
||||||
| `long` / `ulong` | `X10D` | 11 |
|
| `long` / `ulong` | `X10D` | 13 |
|
||||||
| `IList<T>` | `X10D` | 2 |
|
| `IList<T>` | `X10D` | 2 |
|
||||||
| `Random` | `X10D` | 2 |
|
| `Random` | `X10D` | 2 |
|
||||||
| `string` / `SecureString` | `X10D` | 8 |
|
| `string` / `SecureString` | `X10D` | 8 |
|
||||||
|
@ -45,6 +45,28 @@
|
|||||||
return BitConverter.GetBytes(number);
|
return BitConverter.GetBytes(number);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Determines if the <see cref="Single"/> is even.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="number">The number.</param>
|
||||||
|
/// <returns>Returns <see langword="true"/> if <paramref name="number"/> is even, <see langword="false"/>
|
||||||
|
/// otherwise.</returns>
|
||||||
|
public static bool IsEven(this float number)
|
||||||
|
{
|
||||||
|
return ((double) number).IsEven();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Determines if the <see cref="Single"/> is odd.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="number">The number.</param>
|
||||||
|
/// <returns>Returns <see langword="true"/> if <paramref name="number"/> is odd, <see langword="false"/>
|
||||||
|
/// otherwise.</returns>
|
||||||
|
public static bool IsOdd(this float number)
|
||||||
|
{
|
||||||
|
return !number.IsEven();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Converts an angle from radians to degrees.
|
/// Converts an angle from radians to degrees.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
Loading…
Reference in New Issue
Block a user