Skip to content

Commit

Permalink
refactor!: move IsEven/IsOdd to NumberExtensions for .net>=7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverbooth committed Feb 17, 2024
1 parent 3e0853d commit 19c467d
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 45 deletions.
2 changes: 1 addition & 1 deletion X10D/src/Math/ByteExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ public static byte GreatestCommonFactor(this byte value, byte other)
{
return (byte)((long)value).GreatestCommonFactor(other);
}
#endif

/// <summary>
/// Returns a value indicating whether the current value is evenly divisible by 2.
Expand Down Expand Up @@ -109,6 +108,7 @@ public static bool IsOdd(this byte value)
{
return !value.IsEven();
}
#endif

/// <summary>
/// Returns a value indicating whether the current value is a prime number.
Expand Down
2 changes: 1 addition & 1 deletion X10D/src/Math/Int16Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ public static short GreatestCommonFactor(this short value, short other)
{
return (short)((long)value).GreatestCommonFactor(other);
}
#endif

/// <summary>
/// Returns a value indicating whether the current value is evenly divisible by 2.
Expand Down Expand Up @@ -114,6 +113,7 @@ public static bool IsOdd(this short value)
{
return !value.IsEven();
}
#endif

/// <summary>
/// Returns a value indicating whether the current value is a prime number.
Expand Down
2 changes: 1 addition & 1 deletion X10D/src/Math/Int32Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ public static int GreatestCommonFactor(this int value, int other)
{
return (int)((long)value).GreatestCommonFactor(other);
}
#endif

/// <summary>
/// Returns a value indicating whether the current value is evenly divisible by 2.
Expand Down Expand Up @@ -114,6 +113,7 @@ public static bool IsOdd(this int value)
{
return !value.IsEven();
}
#endif

/// <summary>
/// Returns a value indicating whether the current value is a prime number.
Expand Down
2 changes: 1 addition & 1 deletion X10D/src/Math/Int64Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ public static long GreatestCommonFactor(this long value, long other)

return value;
}
#endif

/// <summary>
/// Returns a value indicating whether the current value is evenly divisible by 2.
Expand Down Expand Up @@ -119,6 +118,7 @@ public static bool IsOdd(this long value)
{
return !value.IsEven();
}
#endif

/// <summary>
/// Returns a value indicating whether the current value is a prime number.
Expand Down
2 changes: 1 addition & 1 deletion X10D/src/Math/SByteExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ public static sbyte GreatestCommonFactor(this sbyte value, sbyte other)
{
return (sbyte)((long)value).GreatestCommonFactor(other);
}
#endif

/// <summary>
/// Returns a value indicating whether the current value is evenly divisible by 2.
Expand Down Expand Up @@ -115,6 +114,7 @@ public static bool IsOdd(this sbyte value)
{
return !value.IsEven();
}
#endif

/// <summary>
/// Returns a value indicating whether the current value is a prime number.
Expand Down
24 changes: 12 additions & 12 deletions X10D/src/Math/UInt16Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ public static ushort GreatestCommonFactor(this ushort value, ushort other)
{
return (ushort)((long)value).GreatestCommonFactor(other);
}
#endif

/// <summary>
/// Returns a value indicating whether the current value is evenly divisible by 2.
Expand All @@ -97,32 +96,33 @@ public static bool IsEven(this ushort value)
}

/// <summary>
/// Returns a value indicating whether the current value is a prime number.
/// Returns a value indicating whether the current value is not evenly divisible by 2.
/// </summary>
/// <param name="value">The value whose primality to check.</param>
/// <param name="value">The value whose parity to check.</param>
/// <returns>
/// <see langword="true" /> if <paramref name="value" /> is prime; otherwise, <see langword="false" />.
/// <see langword="true" /> if <paramref name="value" /> is not evenly divisible by 2, or <see langword="false" />
/// otherwise.
/// </returns>
[Pure]
[MethodImpl(CompilerResources.MaxOptimization)]
public static bool IsPrime(this ushort value)
public static bool IsOdd(this ushort value)
{
return ((ulong)value).IsPrime();
return !value.IsEven();
}
#endif

/// <summary>
/// Returns a value indicating whether the current value is not evenly divisible by 2.
/// Returns a value indicating whether the current value is a prime number.
/// </summary>
/// <param name="value">The value whose parity to check.</param>
/// <param name="value">The value whose primality to check.</param>
/// <returns>
/// <see langword="true" /> if <paramref name="value" /> is not evenly divisible by 2, or <see langword="false" />
/// otherwise.
/// <see langword="true" /> if <paramref name="value" /> is prime; otherwise, <see langword="false" />.
/// </returns>
[Pure]
[MethodImpl(CompilerResources.MaxOptimization)]
public static bool IsOdd(this ushort value)
public static bool IsPrime(this ushort value)
{
return !value.IsEven();
return ((ulong)value).IsPrime();
}

/// <summary>
Expand Down
24 changes: 12 additions & 12 deletions X10D/src/Math/UInt32Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ public static uint GreatestCommonFactor(this uint value, uint other)
{
return (uint)((long)value).GreatestCommonFactor(other);
}
#endif

/// <summary>
/// Returns a value indicating whether the current value is evenly divisible by 2.
Expand All @@ -97,32 +96,33 @@ public static bool IsEven(this uint value)
}

/// <summary>
/// Returns a value indicating whether the current value is a prime number.
/// Returns a value indicating whether the current value is not evenly divisible by 2.
/// </summary>
/// <param name="value">The value whose primality to check.</param>
/// <param name="value">The value whose parity to check.</param>
/// <returns>
/// <see langword="true" /> if <paramref name="value" /> is prime; otherwise, <see langword="false" />.
/// <see langword="true" /> if <paramref name="value" /> is not evenly divisible by 2, or <see langword="false" />
/// otherwise.
/// </returns>
[Pure]
[MethodImpl(CompilerResources.MaxOptimization)]
public static bool IsPrime(this uint value)
public static bool IsOdd(this uint value)
{
return ((ulong)value).IsPrime();
return !value.IsEven();
}
#endif

/// <summary>
/// Returns a value indicating whether the current value is not evenly divisible by 2.
/// Returns a value indicating whether the current value is a prime number.
/// </summary>
/// <param name="value">The value whose parity to check.</param>
/// <param name="value">The value whose primality to check.</param>
/// <returns>
/// <see langword="true" /> if <paramref name="value" /> is not evenly divisible by 2, or <see langword="false" />
/// otherwise.
/// <see langword="true" /> if <paramref name="value" /> is prime; otherwise, <see langword="false" />.
/// </returns>
[Pure]
[MethodImpl(CompilerResources.MaxOptimization)]
public static bool IsOdd(this uint value)
public static bool IsPrime(this uint value)
{
return !value.IsEven();
return ((ulong)value).IsPrime();
}

/// <summary>
Expand Down
32 changes: 16 additions & 16 deletions X10D/src/Math/UInt64Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ public static ulong GreatestCommonFactor(this ulong value, ulong other)

return value;
}
#endif

/// <summary>
/// Returns a value indicating whether the current value is evenly divisible by 2.
Expand All @@ -101,6 +100,22 @@ 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(CompilerResources.MaxOptimization)]
public static bool IsOdd(this ulong value)
{
return !value.IsEven();
}
#endif

/// <summary>
/// Returns a value indicating whether the current value is a prime number.
/// </summary>
Expand Down Expand Up @@ -134,21 +149,6 @@ public static bool IsPrime(this ulong value)
return true;
}

/// <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(CompilerResources.MaxOptimization)]
public static bool IsOdd(this ulong value)
{
return !value.IsEven();
}

/// <summary>
/// Calculates the lowest common multiple between the current 64-bit unsigned integer, and another 64-bit unsigned
/// integer.
Expand Down

0 comments on commit 19c467d

Please sign in to comment.