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 | 30 ++++++++++++++--------------- X10D/src/Math/UInt32Extensions.cs | 30 ++++++++++++++--------------- X10D/src/Math/UInt64Extensions.cs | 32 +++++++++++++++---------------- 8 files changed, 51 insertions(+), 51 deletions(-) diff --git a/X10D/src/Math/ByteExtensions.cs b/X10D/src/Math/ByteExtensions.cs index f6a0007..0bd8486 100644 --- a/X10D/src/Math/ByteExtensions.cs +++ b/X10D/src/Math/ByteExtensions.cs @@ -78,7 +78,6 @@ public static class ByteExtensions { 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 class ByteExtensions { 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 2cf6494..318a948 100644 --- a/X10D/src/Math/Int16Extensions.cs +++ b/X10D/src/Math/Int16Extensions.cs @@ -83,7 +83,6 @@ public static class Int16Extensions { 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 class Int16Extensions { 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 bc59f55..e0b05cc 100644 --- a/X10D/src/Math/Int32Extensions.cs +++ b/X10D/src/Math/Int32Extensions.cs @@ -83,7 +83,6 @@ public static class Int32Extensions { 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 class Int32Extensions { 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 4153174..b0c1e58 100644 --- a/X10D/src/Math/Int64Extensions.cs +++ b/X10D/src/Math/Int64Extensions.cs @@ -88,7 +88,6 @@ public static class Int64Extensions return value; } -#endif /// /// Returns a value indicating whether the current value is evenly divisible by 2. @@ -119,6 +118,7 @@ public static class Int64Extensions { 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 ae5c63b..de64ee3 100644 --- a/X10D/src/Math/SByteExtensions.cs +++ b/X10D/src/Math/SByteExtensions.cs @@ -84,7 +84,6 @@ public static class SByteExtensions { 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 class SByteExtensions { 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 9db0e10..617ed9d 100644 --- a/X10D/src/Math/UInt16Extensions.cs +++ b/X10D/src/Math/UInt16Extensions.cs @@ -79,7 +79,6 @@ public static class UInt16Extensions { return (ushort)((long)value).GreatestCommonFactor(other); } -#endif /// /// Returns a value indicating whether the current value is evenly divisible by 2. @@ -96,20 +95,6 @@ public static class UInt16Extensions return (value & 1) == 0; } - /// - /// Returns a value indicating whether the current value is a prime number. - /// - /// The value whose primality to check. - /// - /// if is prime; otherwise, . - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static bool IsPrime(this ushort value) - { - return ((ulong)value).IsPrime(); - } - /// /// Returns a value indicating whether the current value is not evenly divisible by 2. /// @@ -124,6 +109,21 @@ public static class UInt16Extensions { return !value.IsEven(); } +#endif + + /// + /// Returns a value indicating whether the current value is a prime number. + /// + /// The value whose primality to check. + /// + /// if is prime; otherwise, . + /// + [Pure] + [MethodImpl(CompilerResources.MaxOptimization)] + public static bool IsPrime(this ushort value) + { + return ((ulong)value).IsPrime(); + } /// /// Calculates the lowest common multiple between the current 16-bit unsigned integer, and another 16-bit unsigned diff --git a/X10D/src/Math/UInt32Extensions.cs b/X10D/src/Math/UInt32Extensions.cs index d57fad3..da391e9 100644 --- a/X10D/src/Math/UInt32Extensions.cs +++ b/X10D/src/Math/UInt32Extensions.cs @@ -79,7 +79,6 @@ public static class UInt32Extensions { return (uint)((long)value).GreatestCommonFactor(other); } -#endif /// /// Returns a value indicating whether the current value is evenly divisible by 2. @@ -96,20 +95,6 @@ public static class UInt32Extensions return (value & 1) == 0; } - /// - /// Returns a value indicating whether the current value is a prime number. - /// - /// The value whose primality to check. - /// - /// if is prime; otherwise, . - /// - [Pure] - [MethodImpl(CompilerResources.MaxOptimization)] - public static bool IsPrime(this uint value) - { - return ((ulong)value).IsPrime(); - } - /// /// Returns a value indicating whether the current value is not evenly divisible by 2. /// @@ -124,6 +109,21 @@ public static class UInt32Extensions { return !value.IsEven(); } +#endif + + /// + /// Returns a value indicating whether the current value is a prime number. + /// + /// The value whose primality to check. + /// + /// if is prime; otherwise, . + /// + [Pure] + [MethodImpl(CompilerResources.MaxOptimization)] + public static bool IsPrime(this uint value) + { + return ((ulong)value).IsPrime(); + } /// /// Calculates the lowest common multiple between the current 32-bit unsigned integer, and another 32-bit unsigned diff --git a/X10D/src/Math/UInt64Extensions.cs b/X10D/src/Math/UInt64Extensions.cs index 890d703..aaec7b4 100644 --- a/X10D/src/Math/UInt64Extensions.cs +++ b/X10D/src/Math/UInt64Extensions.cs @@ -84,7 +84,6 @@ public static class UInt64Extensions return value; } -#endif /// /// Returns a value indicating whether the current value is evenly divisible by 2. @@ -101,6 +100,22 @@ public static class UInt64Extensions 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 class UInt64Extensions 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.