From b5f448939e39275305dc4330a3a0d45f03b74a6f Mon Sep 17 00:00:00 2001 From: tacosontitan <65432314+tacosontitan@users.noreply.github.com> Date: Sat, 13 Apr 2024 15:12:58 -0500 Subject: [PATCH] Started defining comparison support for byte. --- .../Primitives/Number/Byte/Comparisons.cs | 142 ++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 src/Hussy.Net/Primitives/Number/Byte/Comparisons.cs diff --git a/src/Hussy.Net/Primitives/Number/Byte/Comparisons.cs b/src/Hussy.Net/Primitives/Number/Byte/Comparisons.cs new file mode 100644 index 0000000..453a219 --- /dev/null +++ b/src/Hussy.Net/Primitives/Number/Byte/Comparisons.cs @@ -0,0 +1,142 @@ +namespace Hussy.Net; + +public readonly partial struct Number + : IComparable +{ + /// + public int CompareTo(byte other) + { + if (_value is not IComparable comparable) + throw new InvalidOperationException("The value stored in the number is does not implement IComparable."); + + return comparable.CompareTo(other); + } + + /// + /// Determines if the specified instance is + /// less than the specified instance. + /// + /// The instance to compare. + /// The instance to compare. + /// + /// if the specified instance + /// is less than the specified instance; otherwise, + /// . + /// + public static bool operator <( + Number left, + byte right) => + left.CompareTo(right) < 0; + + /// + /// Determines if the specified instance is + /// less than or equal to the specified instance. + /// + /// The instance to compare. + /// The instance to compare. + /// + /// if the specified instance + /// is less than or equal to the specified instance; + /// otherwise, . + /// + public static bool operator <=( + Number left, + byte right) => + left.CompareTo(right) <= 0; + + /// + /// Determines if the specified instance is + /// greater than the specified instance. + /// + /// The instance to compare. + /// The instance to compare. + /// + /// if the specified instance + /// is greater than the specified instance; otherwise, + /// . + /// + public static bool operator >( + Number left, + byte right) => + left.CompareTo(right) > 0; + + /// + /// Determines if the specified instance is + /// greater than or equal to the specified instance. + /// + /// The instance to compare. + /// The instance to compare. + /// + /// if the specified instance + /// is greater than or equal to the specified instance; + /// otherwise, . + /// + public static bool operator >=( + Number left, + byte right) => + left.CompareTo(right) >= 0; + + /// + /// Determines if the specified instance is + /// less than the specified instance. + /// + /// The instance to compare. + /// The instance to compare. + /// + /// if the specified instance + /// is less than the specified instance; otherwise, + /// . + /// + public static bool operator <( + byte left, + Number right) => + left.CompareTo(right) < 0; + + /// + /// Determines if the specified instance is + /// less than or equal to the specified instance. + /// + /// The instance to compare. + /// The instance to compare. + /// + /// if the specified instance + /// is less than or equal to the specified instance; + /// otherwise, . + /// + public static bool operator <=( + byte left, + Number right) => + left.CompareTo(right) <= 0; + + /// + /// Determines if the specified instance is + /// greater than the specified instance. + /// + /// The instance to compare. + /// The instance to compare. + /// + /// if the specified instance + /// is greater than the specified instance; otherwise, + /// . + /// + public static bool operator >( + byte left, + Number right) => + left.CompareTo(right) > 0; + + /// + /// Determines if the specified instance is + /// greater than or equal to the specified instance. + /// + /// The instance to compare. + /// The instance to compare. + /// + /// if the specified instance + /// is greater than or equal to the specified instance; + /// otherwise, . + /// + public static bool operator >=( + byte left, + Number right) => + left.CompareTo(right) >= 0; +} \ No newline at end of file