1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-22 19:58:49 +00:00

Use n&1 rather than n%2 for integer IsEven check

This commit is contained in:
Oliver Booth 2022-12-06 01:22:48 +00:00
parent 941f3acc56
commit a53cb12d5d
No known key found for this signature in database
GPG Key ID: 32A00B35503AF634
4 changed files with 5 additions and 5 deletions

View File

@ -73,7 +73,7 @@ public static class ByteExtensions
#endif
public static bool IsEven(this byte value)
{
return value % 2 == 0;
return (value & 1) == 0;
}
/// <summary>

View File

@ -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;
}

View File

@ -79,7 +79,7 @@ public static class SByteExtensions
#endif
public static bool IsEven(this sbyte value)
{
return value % 2 == 0;
return (value & 1) == 0;
}
/// <summary>

View File

@ -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;
}