Skip to content

Commit

Permalink
Started defining comparison support for byte.
Browse files Browse the repository at this point in the history
  • Loading branch information
tacosontitan committed Jun 18, 2024
1 parent 3462f8e commit 23a74fe
Showing 1 changed file with 142 additions and 0 deletions.
142 changes: 142 additions & 0 deletions src/Hussy.Net/Primitives/Number/Byte/Comparisons.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
namespace Hussy.Net;

public readonly partial struct Number
: IComparable<byte>
{
/// <inheritdoc />
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);
}

/// <summary>
/// Determines if the specified <see cref="Number"/> instance is
/// less than the specified <see cref="byte"/> instance.
/// </summary>
/// <param name="left">The <see cref="Number"/> instance to compare.</param>
/// <param name="right">The <see cref="byte"/> instance to compare.</param>
/// <returns>
/// <see langword="true"/> if the specified <see cref="Number"/> instance
/// is less than the specified <see cref="byte"/> instance; otherwise,
/// <see langword="false"/>.
/// </returns>
public static bool operator <(
Number left,
byte right) =>
left.CompareTo(right) < 0;

/// <summary>
/// Determines if the specified <see cref="Number"/> instance is
/// less than or equal to the specified <see cref="byte"/> instance.
/// </summary>
/// <param name="left">The <see cref="Number"/> instance to compare.</param>
/// <param name="right">The <see cref="byte"/> instance to compare.</param>
/// <returns>
/// <see langword="true"/> if the specified <see cref="Number"/> instance
/// is less than or equal to the specified <see cref="byte"/> instance;
/// otherwise, <see langword="false"/>.
/// </returns>
public static bool operator <=(
Number left,
byte right) =>
left.CompareTo(right) <= 0;

/// <summary>
/// Determines if the specified <see cref="Number"/> instance is
/// greater than the specified <see cref="byte"/> instance.
/// </summary>
/// <param name="left">The <see cref="Number"/> instance to compare.</param>
/// <param name="right">The <see cref="byte"/> instance to compare.</param>
/// <returns>
/// <see langword="true"/> if the specified <see cref="Number"/> instance
/// is greater than the specified <see cref="byte"/> instance; otherwise,
/// <see langword="false"/>.
/// </returns>
public static bool operator >(
Number left,
byte right) =>
left.CompareTo(right) > 0;

/// <summary>
/// Determines if the specified <see cref="Number"/> instance is
/// greater than or equal to the specified <see cref="byte"/> instance.
/// </summary>
/// <param name="left">The <see cref="Number"/> instance to compare.</param>
/// <param name="right">The <see cref="byte"/> instance to compare.</param>
/// <returns>
/// <see langword="true"/> if the specified <see cref="Number"/> instance
/// is greater than or equal to the specified <see cref="byte"/> instance;
/// otherwise, <see langword="false"/>.
/// </returns>
public static bool operator >=(
Number left,
byte right) =>
left.CompareTo(right) >= 0;

/// <summary>
/// Determines if the specified <see cref="byte"/> instance is
/// less than the specified <see cref="Number"/> instance.
/// </summary>
/// <param name="left">The <see cref="byte"/> instance to compare.</param>
/// <param name="right">The <see cref="Number"/> instance to compare.</param>
/// <returns>
/// <see langword="true"/> if the specified <see cref="byte"/> instance
/// is less than the specified <see cref="Number"/> instance; otherwise,
/// <see langword="false"/>.
/// </returns>
public static bool operator <(
byte left,
Number right) =>
left.CompareTo(right) < 0;

/// <summary>
/// Determines if the specified <see cref="byte"/> instance is
/// less than or equal to the specified <see cref="Number"/> instance.
/// </summary>
/// <param name="left">The <see cref="byte"/> instance to compare.</param>
/// <param name="right">The <see cref="Number"/> instance to compare.</param>
/// <returns>
/// <see langword="true"/> if the specified <see cref="byte"/> instance
/// is less than or equal to the specified <see cref="Number"/> instance;
/// otherwise, <see langword="false"/>.
/// </returns>
public static bool operator <=(
byte left,
Number right) =>
left.CompareTo(right) <= 0;

/// <summary>
/// Determines if the specified <see cref="byte"/> instance is
/// greater than the specified <see cref="Number"/> instance.
/// </summary>
/// <param name="left">The <see cref="byte"/> instance to compare.</param>
/// <param name="right">The <see cref="Number"/> instance to compare.</param>
/// <returns>
/// <see langword="true"/> if the specified <see cref="byte"/> instance
/// is greater than the specified <see cref="Number"/> instance; otherwise,
/// <see langword="false"/>.
/// </returns>
public static bool operator >(
byte left,
Number right) =>
left.CompareTo(right) > 0;

/// <summary>
/// Determines if the specified <see cref="byte"/> instance is
/// greater than or equal to the specified <see cref="Number"/> instance.
/// </summary>
/// <param name="left">The <see cref="byte"/> instance to compare.</param>
/// <param name="right">The <see cref="Number"/> instance to compare.</param>
/// <returns>
/// <see langword="true"/> if the specified <see cref="byte"/> instance
/// is greater than or equal to the specified <see cref="Number"/> instance;
/// otherwise, <see langword="false"/>.
/// </returns>
public static bool operator >=(
byte left,
Number right) =>
left.CompareTo(right) >= 0;
}

0 comments on commit 23a74fe

Please sign in to comment.