Gorgon
Show / Hide Table of Contents

Struct GorgonRationalNumber

A representation of a rational number.

Implements
IEquatable<GorgonRationalNumber>
IComparable<GorgonRationalNumber>
Inherited Members
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetType()
Namespace: Gorgon.Math
Assembly: Gorgon.Core.dll
Syntax
public readonly struct GorgonRationalNumber : IEquatable<GorgonRationalNumber>, IComparable<GorgonRationalNumber>

Constructors

| Edit this page View Source

GorgonRationalNumber(int, int)

Initializes a new instance of the GorgonRationalNumber struct.

Declaration
public GorgonRationalNumber(int numerator, int denominator)
Parameters
Type Name Description
int numerator

The numerator for the number.

int denominator

The denominator for the number.

Exceptions
Type Condition
DivideByZeroException

Thrown when the denominator is 0.

Fields

| Edit this page View Source

Denominator

The denominator for the number.

Declaration
public readonly int Denominator
Field Value
Type Description
int
| Edit this page View Source

Empty

An empty rational number.

Declaration
public static readonly GorgonRationalNumber Empty
Field Value
Type Description
GorgonRationalNumber
| Edit this page View Source

Numerator

The numerator for the number.

Declaration
public readonly int Numerator
Field Value
Type Description
int

Methods

| Edit this page View Source

CompareTo(GorgonRationalNumber)

Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.

Declaration
public int CompareTo(GorgonRationalNumber other)
Parameters
Type Name Description
GorgonRationalNumber other

An object to compare with this instance.

Returns
Type Description
int

A value that indicates the relative order of the objects being compared. The return value has these meanings: Value Meaning Less than zero This instance precedes other in the sort order. Zero This instance occurs in the same position in the sort order as other. Greater than zero This instance follows other in the sort order.

| Edit this page View Source

Equals(GorgonRationalNumber)

Indicates whether the current object is equal to another object of the same type.

Declaration
public bool Equals(GorgonRationalNumber other)
Parameters
Type Name Description
GorgonRationalNumber other

An object to compare with this object.

Returns
Type Description
bool

true if the current object is equal to the other parameter; otherwise, false.

| Edit this page View Source

Equals(GorgonRationalNumber, GorgonRationalNumber)

Function to compare two instances for equality.

Declaration
public static bool Equals(GorgonRationalNumber left, GorgonRationalNumber right)
Parameters
Type Name Description
GorgonRationalNumber left

Left instance to compare.

GorgonRationalNumber right

Right instance to compare.

Returns
Type Description
bool

true if the instances are equal, false if not.

| Edit this page View Source

Equals(object)

Determines whether the specified object is equal to the current object.

Declaration
public override bool Equals(object obj)
Parameters
Type Name Description
object obj

The object to compare with the current object.

Returns
Type Description
bool

true if the specified object is equal to the current object; otherwise, false.

Overrides
ValueType.Equals(object)
| Edit this page View Source

GetHashCode()

Serves as the default hash function.

Declaration
public override int GetHashCode()
Returns
Type Description
int

A hash code for the current object.

Overrides
ValueType.GetHashCode()
| Edit this page View Source

ToDecimal(GorgonRationalNumber)

Function to perform an implicit conversion from GorgonRationalNumber to decimal.

Declaration
public static decimal ToDecimal(GorgonRationalNumber value)
Parameters
Type Name Description
GorgonRationalNumber value

The value convert.

Returns
Type Description
decimal

The result of the conversion.

| Edit this page View Source

ToDouble(GorgonRationalNumber)

Function to perform an explicit conversion from GorgonRationalNumber to double.

Declaration
public static double ToDouble(GorgonRationalNumber value)
Parameters
Type Name Description
GorgonRationalNumber value

The value convert.

Returns
Type Description
double

The result of the conversion.

| Edit this page View Source

ToGorgonRationalNumber(int)

Function to perform an implicit conversion from int to GorgonRationalNumber.

Declaration
public static GorgonRationalNumber ToGorgonRationalNumber(int value)
Parameters
Type Name Description
int value

The value to convert.

Returns
Type Description
GorgonRationalNumber

The result of the conversion.

| Edit this page View Source

ToInt32(GorgonRationalNumber)

Function to perform an explicit conversion from GorgonRationalNumber to int.

Declaration
public static int ToInt32(GorgonRationalNumber value)
Parameters
Type Name Description
GorgonRationalNumber value

The value convert.

Returns
Type Description
int

The result of the conversion.

| Edit this page View Source

ToSingle(GorgonRationalNumber)

Function to perform an explicit conversion from GorgonRationalNumber to float.

Declaration
public static float ToSingle(GorgonRationalNumber value)
Parameters
Type Name Description
GorgonRationalNumber value

The value convert.

Returns
Type Description
float

The result of the conversion.

| Edit this page View Source

ToString()

Returns a string that represents the current object.

Declaration
public override string ToString()
Returns
Type Description
string

A string that represents the current object.

Overrides
ValueType.ToString()

Operators

| Edit this page View Source

operator ==(GorgonRationalNumber, GorgonRationalNumber)

Operator to compare two instances for equality.

Declaration
public static bool operator ==(GorgonRationalNumber left, GorgonRationalNumber right)
Parameters
Type Name Description
GorgonRationalNumber left

Left instance to compare.

GorgonRationalNumber right

Right instance to compare.

Returns
Type Description
bool

true if equal, false if not.

| Edit this page View Source

explicit operator double(GorgonRationalNumber)

Performs an explicit conversion from GorgonRationalNumber to double.

Declaration
public static explicit operator double(GorgonRationalNumber value)
Parameters
Type Name Description
GorgonRationalNumber value

The value convert.

Returns
Type Description
double

The result of the conversion.

| Edit this page View Source

explicit operator int(GorgonRationalNumber)

Performs an explicit conversion from GorgonRationalNumber to int.

Declaration
public static explicit operator int(GorgonRationalNumber value)
Parameters
Type Name Description
GorgonRationalNumber value

The value convert.

Returns
Type Description
int

The result of the conversion.

| Edit this page View Source

explicit operator float(GorgonRationalNumber)

Performs an explicit conversion from GorgonRationalNumber to float.

Declaration
public static explicit operator float(GorgonRationalNumber value)
Parameters
Type Name Description
GorgonRationalNumber value

The value convert.

Returns
Type Description
float

The result of the conversion.

| Edit this page View Source

operator >(GorgonRationalNumber, GorgonRationalNumber)

Operator to determine if the left rational is greater than the right rational.

Declaration
public static bool operator >(GorgonRationalNumber left, GorgonRationalNumber right)
Parameters
Type Name Description
GorgonRationalNumber left

Left rational to compare.

GorgonRationalNumber right

Right rational to compare.

Returns
Type Description
bool

true if the left is greater than the right, false if not.

| Edit this page View Source

operator >=(GorgonRationalNumber, GorgonRationalNumber)

Operator to determine if the left rational is greater than or equal to the right rational.

Declaration
public static bool operator >=(GorgonRationalNumber left, GorgonRationalNumber right)
Parameters
Type Name Description
GorgonRationalNumber left

Left rational to compare.

GorgonRationalNumber right

Right rational to compare.

Returns
Type Description
bool

true if the left is greater than or equal to the right, false if not.

| Edit this page View Source

implicit operator decimal(GorgonRationalNumber)

Performs an implicit conversion from GorgonRationalNumber to decimal.

Declaration
public static implicit operator decimal(GorgonRationalNumber value)
Parameters
Type Name Description
GorgonRationalNumber value

The value convert.

Returns
Type Description
decimal

The result of the conversion.

| Edit this page View Source

implicit operator GorgonRationalNumber(int)

Performs an implicit conversion from int to GorgonRationalNumber.

Declaration
public static implicit operator GorgonRationalNumber(int value)
Parameters
Type Name Description
int value

The value to convert.

Returns
Type Description
GorgonRationalNumber

The result of the conversion.

| Edit this page View Source

operator !=(GorgonRationalNumber, GorgonRationalNumber)

Operator to compare two instances for inequality.

Declaration
public static bool operator !=(GorgonRationalNumber left, GorgonRationalNumber right)
Parameters
Type Name Description
GorgonRationalNumber left

Left instance to compare.

GorgonRationalNumber right

Right instance to compare.

Returns
Type Description
bool

true if not equal, false if equal.

| Edit this page View Source

operator <(GorgonRationalNumber, GorgonRationalNumber)

Operator to determine if the left rational is less than the right rational.

Declaration
public static bool operator <(GorgonRationalNumber left, GorgonRationalNumber right)
Parameters
Type Name Description
GorgonRationalNumber left

Left rational to compare.

GorgonRationalNumber right

Right rational to compare.

Returns
Type Description
bool

true if the left is less than the right, false if not.

| Edit this page View Source

operator <=(GorgonRationalNumber, GorgonRationalNumber)

Operator to determine if the left rational is less than or equal to the right rational.

Declaration
public static bool operator <=(GorgonRationalNumber left, GorgonRationalNumber right)
Parameters
Type Name Description
GorgonRationalNumber left

Left rational to compare.

GorgonRationalNumber right

Right rational to compare.

Returns
Type Description
bool

true if the left is less than or equal to the right, false if not.

Implements

IEquatable<T>
IComparable<T>

Extension Methods

GorgonNullExtensions.AsNullable<T>(object)
GorgonNullExtensions.IfNull<T>(object, T)
GorgonNullExtensions.IsNull(object)
  • Edit this page
  • View Source
In this article
Back to top Copyright 2023 - Licensed under the MIT license by Michael Winsor (Tape_Worm).
Send comments on this topic to the author