From 19c467d88b2b5ed551f43dc19b6c3a463c7091e5 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Sat, 17 Feb 2024 18:23:55 +0000 Subject: [PATCH] refactor!: move IsEven/IsOdd to NumberExtensions for .net>=7.0 --- X10D/src/Math/ByteExtensions.cs | 2 +- X10D/src/Math/Int16Extensions.cs | 2 +- X10D/src/Math/Int32Extensions.cs | 2 +- X10D/src/Math/Int64Extensions.cs | 2 +- X10D/src/Math/SByteExtensions.cs | 2 +- X10D/src/Math/UInt16Extensions.cs | 24 +++++++++++------------ X10D/src/Math/UInt32Extensions.cs | 24 +++++++++++------------ X10D/src/Math/UInt64Extensions.cs | 32 +++++++++++++++---------------- 8 files changed, 45 insertions(+), 45 deletions(-) diff --git a/X10D/src/Math/ByteExtensions.cs b/X10D/src/Math/ByteExtensions.cs index f6a000732..0bd8486c2 100644 --- a/X10D/src/Math/ByteExtensions.cs +++ b/X10D/src/Math/ByteExtensions.cs @@ -78,7 +78,6 @@ public static byte GreatestCommonFactor(this byte value, byte other) { return (byte)((long)value).GreatestCommonFactor(other); } -#endif /// /// Returns a value indicating whether the current value is evenly divisible by 2. @@ -109,6 +108,7 @@ public static bool IsOdd(this byte value) { return !value.IsEven(); } +#endif /// /// Returns a value indicating whether the current value is a prime number. diff --git a/X10D/src/Math/Int16Extensions.cs b/X10D/src/Math/Int16Extensions.cs index 2cf6494de..318a9488a 100644 --- a/X10D/src/Math/Int16Extensions.cs +++ b/X10D/src/Math/Int16Extensions.cs @@ -83,7 +83,6 @@ public static short GreatestCommonFactor(this short value, short other) { return (short)((long)value).GreatestCommonFactor(other); } -#endif /// /// Returns a value indicating whether the current value is evenly divisible by 2. @@ -114,6 +113,7 @@ public static bool IsOdd(this short value) { return !value.IsEven(); } +#endif /// /// Returns a value indicating whether the current value is a prime number. diff --git a/X10D/src/Math/Int32Extensions.cs b/X10D/src/Math/Int32Extensions.cs index bc59f5506..e0b05cc74 100644 --- a/X10D/src/Math/Int32Extensions.cs +++ b/X10D/src/Math/Int32Extensions.cs @@ -83,7 +83,6 @@ public static int GreatestCommonFactor(this int value, int other) { return (int)((long)value).GreatestCommonFactor(other); } -#endif /// /// Returns a value indicating whether the current value is evenly divisible by 2. @@ -114,6 +113,7 @@ public static bool IsOdd(this int value) { return !value.IsEven(); } +#endif /// /// Returns a value indicating whether the current value is a prime number. diff --git a/X10D/src/Math/Int64Extensions.cs b/X10D/src/Math/Int64Extensions.cs index 4153174b3..b0c1e58bb 100644 --- a/X10D/src/Math/Int64Extensions.cs +++ b/X10D/src/Math/Int64Extensions.cs @@ -88,7 +88,6 @@ public static long GreatestCommonFactor(this long value, long other) return value; } -#endif /// /// Returns a value indicating whether the current value is evenly divisible by 2. @@ -119,6 +118,7 @@ public static bool IsOdd(this long value) { return !value.IsEven(); } +#endif /// /// Returns a value indicating whether the current value is a prime number. diff --git a/X10D/src/Math/SByteExtensions.cs b/X10D/src/Math/SByteExtensions.cs index ae5c63b95..de64ee3e8 100644 --- a/X10D/src/Math/SByteExtensions.cs +++ b/X10D/src/Math/SByteExtensions.cs @@ -84,7 +84,6 @@ public static sbyte GreatestCommonFactor(this sbyte value, sbyte other) { return (sbyte)((long)value).GreatestCommonFactor(other); } -#endif /// /// Returns a value indicating whether the current value is evenly divisible by 2. @@ -115,6 +114,7 @@ public static bool IsOdd(this sbyte value) { return !value.IsEven(); } +#endif /// /// Returns a value indicating whether the current value is a prime number. diff --git a/X10D/src/Math/UInt16Extensions.cs b/X10D/src/Math/UInt16Extensions.cs index 9db0e10b7..617ed9d98 100644 --- a/X10D/src/Math/UInt16Extensions.cs +++ b/X10D/src/Math/UInt16Extensions.cs @@ -79,7 +79,6 @@ public static ushort GreatestCommonFactor(this ushort value, ushort other) { return (ushort)((long)value).GreatestCommonFactor(other); } -#endif /// /// Returns a value indicating whether the current value is evenly divisible by 2. @@ -97,32 +96,33 @@ public static bool IsEven(this ushort value) } /// - /// 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. /// - /// The value whose primality to check. + /// The value whose parity to check. /// - /// if is prime; otherwise, . + /// if is not evenly divisible by 2, or + /// otherwise. /// [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 /// - /// 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. /// - /// The value whose parity to check. + /// The value whose primality to check. /// - /// if is not evenly divisible by 2, or - /// otherwise. + /// if is prime; otherwise, . /// [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(); } /// diff --git a/X10D/src/Math/UInt32Extensions.cs b/X10D/src/Math/UInt32Extensions.cs index d57fad362..da391e98e 100644 --- a/X10D/src/Math/UInt32Extensions.cs +++ b/X10D/src/Math/UInt32Extensions.cs @@ -79,7 +79,6 @@ public static uint GreatestCommonFactor(this uint value, uint other) { return (uint)((long)value).GreatestCommonFactor(other); } -#endif /// /// Returns a value indicating whether the current value is evenly divisible by 2. @@ -97,32 +96,33 @@ public static bool IsEven(this uint value) } /// - /// 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. /// - /// The value whose primality to check. + /// The value whose parity to check. /// - /// if is prime; otherwise, . + /// if is not evenly divisible by 2, or + /// otherwise. /// [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 /// - /// 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. /// - /// The value whose parity to check. + /// The value whose primality to check. /// - /// if is not evenly divisible by 2, or - /// otherwise. + /// if is prime; otherwise, . /// [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(); } /// diff --git a/X10D/src/Math/UInt64Extensions.cs b/X10D/src/Math/UInt64Extensions.cs index 890d70313..aaec7b454 100644 --- a/X10D/src/Math/UInt64Extensions.cs +++ b/X10D/src/Math/UInt64Extensions.cs @@ -84,7 +84,6 @@ public static ulong GreatestCommonFactor(this ulong value, ulong other) return value; } -#endif /// /// Returns a value indicating whether the current value is evenly divisible by 2. @@ -101,6 +100,22 @@ public static bool IsEven(this ulong value) return (value & 1) == 0; } + /// + /// Returns a value indicating whether the current value is not evenly divisible by 2. + /// + /// The value whose parity to check. + /// + /// if is not evenly divisible by 2, or + /// otherwise. + /// + [Pure] + [MethodImpl(CompilerResources.MaxOptimization)] + public static bool IsOdd(this ulong value) + { + return !value.IsEven(); + } +#endif + /// /// Returns a value indicating whether the current value is a prime number. /// @@ -134,21 +149,6 @@ public static bool IsPrime(this ulong value) return true; } - /// - /// Returns a value indicating whether the current value is not evenly divisible by 2. - /// - /// The value whose parity to check. - /// - /// if is not evenly divisible by 2, or - /// otherwise. - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static bool IsOdd(this ulong value) - { - return !value.IsEven(); - } - /// /// Calculates the lowest common multiple between the current 64-bit unsigned integer, and another 64-bit unsigned /// integer.