-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Started defining comparison support for byte.
- Loading branch information
1 parent
173af8a
commit b5f4489
Showing
1 changed file
with
142 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
namespace Hussy.Net; | ||
|
||
public readonly partial struct Number | ||
Check warning on line 3 in src/Hussy.Net/Primitives/Number/Byte/Comparisons.cs
|
||
: 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; | ||
} |