diff --git a/X10D/DoubleExtensions.cs b/X10D/DoubleExtensions.cs index 3fa650b..424a218 100644 --- a/X10D/DoubleExtensions.cs +++ b/X10D/DoubleExtensions.cs @@ -45,6 +45,28 @@ return BitConverter.GetBytes(number); } + /// + /// Determines if the is even. + /// + /// The number. + /// Returns if is even, + /// otherwise. + public static bool IsEven(this double number) + { + return Math.Abs(number % 2.0) < Double.Epsilon; + } + + /// + /// Determines if the is odd. + /// + /// The number. + /// Returns if is odd, + /// otherwise. + public static bool IsOdd(this double number) + { + return !number.IsEven(); + } + /// /// Converts an angle from radians to degrees. /// diff --git a/X10D/Int16Extensions.cs b/X10D/Int16Extensions.cs index 85914fa..9c598f9 100644 --- a/X10D/Int16Extensions.cs +++ b/X10D/Int16Extensions.cs @@ -138,6 +138,50 @@ return BitConverter.GetBytes(number); } + /// + /// Determines if the is even. + /// + /// The number. + /// Returns if is even, + /// otherwise. + public static bool IsEven(this short number) + { + return ((long) number).IsEven(); + } + + /// + /// Determines if the is even. + /// + /// The number. + /// Returns if is even, + /// otherwise. + public static bool IsEven(this ushort number) + { + return ((ulong) number).IsEven(); + } + + /// + /// Determines if the is odd. + /// + /// The number. + /// Returns if is odd, + /// otherwise. + public static bool IsOdd(this short number) + { + return !number.IsEven(); + } + + /// + /// Determines if the is odd. + /// + /// The number. + /// Returns if is odd, + /// otherwise. + public static bool IsOdd(this ushort number) + { + return !number.IsEven(); + } + /// /// Determines if the is a prime number. /// @@ -149,6 +193,17 @@ return ((long) number).IsPrime(); } + /// + /// Determines if the is a prime number. + /// + /// The number. + /// Returns if is prime, + /// otherwise. + public static bool IsPrime(this ushort number) + { + return ((ulong) number).IsPrime(); + } + /// /// Gets an boolean value that represents this integer. /// diff --git a/X10D/Int32Extensions.cs b/X10D/Int32Extensions.cs index 42a36b3..571714d 100644 --- a/X10D/Int32Extensions.cs +++ b/X10D/Int32Extensions.cs @@ -298,6 +298,50 @@ return BitConverter.GetBytes(number); } + /// + /// Determines if the is even. + /// + /// The number. + /// Returns if is even, + /// otherwise. + public static bool IsEven(this int number) + { + return ((long)number).IsEven(); + } + + /// + /// Determines if the is even. + /// + /// The number. + /// Returns if is even, + /// otherwise. + public static bool IsEven(this uint number) + { + return ((ulong)number).IsEven(); + } + + /// + /// Determines if the is odd. + /// + /// The number. + /// Returns if is odd, + /// otherwise. + public static bool IsOdd(this int number) + { + return !number.IsEven(); + } + + /// + /// Determines if the is odd. + /// + /// The number. + /// Returns if is odd, + /// otherwise. + public static bool IsOdd(this uint number) + { + return !number.IsEven(); + } + /// /// Determines if the is a prime number. /// diff --git a/X10D/Int64Extensions.cs b/X10D/Int64Extensions.cs index fc605f4..908df84 100644 --- a/X10D/Int64Extensions.cs +++ b/X10D/Int64Extensions.cs @@ -137,6 +137,50 @@ return BitConverter.GetBytes(number); } + /// + /// Determines if the is even. + /// + /// The number. + /// Returns if is even, + /// otherwise. + public static bool IsEven(this long number) + { + return Math.Abs(number % 2.0) < Double.Epsilon; + } + + /// + /// Determines if the is even. + /// + /// The number. + /// Returns if is even, + /// otherwise. + public static bool IsEven(this ulong number) + { + return Math.Abs(number % 2.0) < Double.Epsilon; + } + + /// + /// Determines if the is odd. + /// + /// The number. + /// Returns if is odd, + /// otherwise. + public static bool IsOdd(this long number) + { + return !IsEven(number); + } + + /// + /// Determines if the is odd. + /// + /// The number. + /// Returns if is odd, + /// otherwise. + public static bool IsOdd(this ulong number) + { + return !IsEven(number); + } + /// /// Determines if the is a prime number. /// diff --git a/X10D/README.md b/X10D/README.md index 991d92c..f185661 100644 --- a/X10D/README.md +++ b/X10D/README.md @@ -15,12 +15,12 @@ Below is a list of the number of extension methods written for a given type. Ove | `IConvertible` | `X10D` | 4 | | `DateTime` | `X10D` | 11 | | `EndPoint` | `X10D` | 2 | -| `double` | `X10D` | 5 | +| `double` | `X10D` | 7 | | `enum` | `X10D` | 2 | -| `float` | `X10D` | 5 | +| `float` | `X10D` | 7 | | `short` / `ushort` | `X10D` | 11 | -| `int` / `uint` | `X10D` | 23 | -| `long` / `ulong` | `X10D` | 11 | +| `int` / `uint` | `X10D` | 25 | +| `long` / `ulong` | `X10D` | 13 | | `IList` | `X10D` | 2 | | `Random` | `X10D` | 2 | | `string` / `SecureString` | `X10D` | 8 | diff --git a/X10D/SingleExtensions.cs b/X10D/SingleExtensions.cs index f3b65f6..9a27c85 100644 --- a/X10D/SingleExtensions.cs +++ b/X10D/SingleExtensions.cs @@ -45,6 +45,28 @@ return BitConverter.GetBytes(number); } + /// + /// Determines if the is even. + /// + /// The number. + /// Returns if is even, + /// otherwise. + public static bool IsEven(this float number) + { + return ((double) number).IsEven(); + } + + /// + /// Determines if the is odd. + /// + /// The number. + /// Returns if is odd, + /// otherwise. + public static bool IsOdd(this float number) + { + return !number.IsEven(); + } + /// /// Converts an angle from radians to degrees. ///