From a53cb12d5de3104e106edd7963058a94dcac6458 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Tue, 6 Dec 2022 01:22:48 +0000 Subject: [PATCH] Use n&1 rather than n%2 for integer IsEven check --- X10D/src/Math/ByteExtensions.cs | 2 +- X10D/src/Math/Int64Extensions.cs | 2 +- X10D/src/Math/SByteExtensions.cs | 2 +- X10D/src/Math/UInt64Extensions.cs | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/X10D/src/Math/ByteExtensions.cs b/X10D/src/Math/ByteExtensions.cs index 310c4e4..ca68dd6 100644 --- a/X10D/src/Math/ByteExtensions.cs +++ b/X10D/src/Math/ByteExtensions.cs @@ -73,7 +73,7 @@ public static class ByteExtensions #endif public static bool IsEven(this byte value) { - return value % 2 == 0; + return (value & 1) == 0; } /// diff --git a/X10D/src/Math/Int64Extensions.cs b/X10D/src/Math/Int64Extensions.cs index 01f10fa..fdb920b 100644 --- a/X10D/src/Math/Int64Extensions.cs +++ b/X10D/src/Math/Int64Extensions.cs @@ -121,7 +121,7 @@ public static class Int64Extensions case <= 3: return true; } - if (value % 2 == 0 || value % 3 == 0) + if ((value & 1) == 0 || value % 3 == 0) { return false; } diff --git a/X10D/src/Math/SByteExtensions.cs b/X10D/src/Math/SByteExtensions.cs index 07252ef..f77d56d 100644 --- a/X10D/src/Math/SByteExtensions.cs +++ b/X10D/src/Math/SByteExtensions.cs @@ -79,7 +79,7 @@ public static class SByteExtensions #endif public static bool IsEven(this sbyte value) { - return value % 2 == 0; + return (value & 1) == 0; } /// diff --git a/X10D/src/Math/UInt64Extensions.cs b/X10D/src/Math/UInt64Extensions.cs index f081236..9d2efbc 100644 --- a/X10D/src/Math/UInt64Extensions.cs +++ b/X10D/src/Math/UInt64Extensions.cs @@ -1,4 +1,4 @@ -using System.Diagnostics.Contracts; +using System.Diagnostics.Contracts; using System.Runtime.CompilerServices; namespace X10D.Math; @@ -97,7 +97,7 @@ public static class UInt64Extensions case <= 3: return true; } - if (value % 2 == 0 || value % 3 == 0) + if ((value & 1) == 0 || value % 3 == 0) { return false; }