Struct Rational
Implements a rational value.
Implements
System.IComparable
System.Runtime.Serialization.IDeserializationCallback
System.Runtime.Serialization.ISerializable
Assembly: Emby.Media.Model.dll
[Serializable]
[TypeConverter(typeof(RationalTypeConverter))]
public struct Rational : IComparable, IComparable<Rational>, IDeserializationCallback, IEquatable<Rational>, ISerializable
Constructors
Initializes a new instance of the Rational struct.
Declaration
public Rational(decimal value, string delimiter = "/")
Parameters
Type |
Name |
Description |
System.Decimal |
value |
The value.
|
System.String |
delimiter |
The delimiter.
|
Exceptions
Type |
Condition |
System.ArgumentException |
invalid Decimal - value
|
Initializes a new instance of the Rational struct.
Declaration
public Rational(double value, string delimiter = "/")
Parameters
Type |
Name |
Description |
System.Double |
value |
The value.
|
System.String |
delimiter |
The delimiter.
|
Exceptions
Type |
Condition |
System.ArgumentException |
Argument is not a number - value
or
Argument is infinity - value
|
Initializes a new instance of the Rational struct.
Declaration
public Rational(BigInteger whole, BigInteger numerator, BigInteger denominator, string delimiter = "/")
Parameters
Type |
Name |
Description |
System.Numerics.BigInteger |
whole |
The whole.
|
System.Numerics.BigInteger |
numerator |
The numerator.
|
System.Numerics.BigInteger |
denominator |
The denominator.
|
System.String |
delimiter |
The delimiter.
|
Exceptions
Type |
Condition |
System.DivideByZeroException |
|
Initializes a new instance of the Rational struct.
Declaration
public Rational(BigInteger numerator, BigInteger denominator, string delimiter = "/")
Parameters
Type |
Name |
Description |
System.Numerics.BigInteger |
numerator |
The numerator.
|
System.Numerics.BigInteger |
denominator |
The denominator.
|
System.String |
delimiter |
The delimiter.
|
Exceptions
Type |
Condition |
System.DivideByZeroException |
|
Initializes a new instance of the Rational struct.
Declaration
public Rational(BigInteger numerator, string delimiter = "/")
Parameters
Type |
Name |
Description |
System.Numerics.BigInteger |
numerator |
The numerator.
|
System.String |
delimiter |
The delimiter.
|
Fields
Declaration
public const string DefaultDelimiter = "/"
Field Value
Type |
Description |
System.String |
|
Properties
Declaration
public readonly BigInteger Denominator { get; }
Property Value
Type |
Description |
System.Numerics.BigInteger |
The denominator.
|
Declaration
public static readonly Rational MinusOne { get; }
Property Value
Type |
Description |
Rational |
The minus one.
|
Declaration
public readonly BigInteger Numerator { get; }
Property Value
Type |
Description |
System.Numerics.BigInteger |
The numerator.
|
Declaration
public static readonly Rational One { get; }
Property Value
Declaration
public readonly int Sign { get; }
Property Value
Type |
Description |
System.Int32 |
The sign.
|
Declaration
public static readonly Rational Zero { get; }
Property Value
Methods
Declaration
public static Rational Abs(Rational r)
Parameters
Returns
Declaration
public static Rational Add(Rational x, Rational y)
Parameters
Returns
Compares the specified r1.
Declaration
public static int Compare(Rational r1, Rational r2)
Parameters
Returns
Type |
Description |
System.Int32 |
|
Declaration
public int CompareTo(Rational other)
Parameters
Type |
Name |
Description |
Rational |
other |
The other.
|
Returns
Type |
Description |
System.Int32 |
|
Divides the specified dividend.
Declaration
public static Rational Divide(Rational dividend, Rational divisor)
Parameters
Type |
Name |
Description |
Rational |
dividend |
The dividend.
|
Rational |
divisor |
The divisor.
|
Returns
Declaration
public static Rational DivRem(Rational dividend, Rational divisor, out Rational remainder)
Parameters
Returns
Indicates whether the current object is equal to another object of the same type.
Declaration
public bool Equals(Rational other)
Parameters
Type |
Name |
Description |
Rational |
other |
An object to compare with this object.
|
Returns
Type |
Description |
System.Boolean |
true if the current object is equal to the other parameter; otherwise, false.
|
Determines whether the specified System.Object, is equal to this instance.
Declaration
public override bool Equals(object obj)
Parameters
Type |
Name |
Description |
System.Object |
obj |
The System.Object to compare with this instance.
|
Returns
Type |
Description |
System.Boolean |
true if the specified System.Object is equal to this instance; otherwise, false .
|
Overrides
System.ValueType.Equals(System.Object)
Declaration
public Rational GetFractionPart()
Returns
Returns a hash code for this instance.
Declaration
public override int GetHashCode()
Returns
Type |
Description |
System.Int32 |
A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
|
Overrides
System.ValueType.GetHashCode()
Declaration
public BigInteger GetWholePart()
Returns
Type |
Description |
System.Numerics.BigInteger |
|
Declaration
public static Rational Invert(Rational r)
Parameters
Returns
Least common denominator.
Declaration
public static BigInteger LeastCommonDenominator(Rational x, Rational y)
Parameters
Returns
Type |
Description |
System.Numerics.BigInteger |
|
Multiplies the specified x.
Declaration
public static Rational Multiply(Rational x, Rational y)
Parameters
Returns
Declaration
public static Rational Negate(Rational r)
Parameters
Returns
Pows the specified base value.
Declaration
public static Rational Pow(Rational baseValue, BigInteger exponent)
Parameters
Type |
Name |
Description |
Rational |
baseValue |
The base value.
|
System.Numerics.BigInteger |
exponent |
The exponent.
|
Returns
Exceptions
Type |
Condition |
System.ArgumentException |
cannot raise zero to a negative power - baseValue
|
Remainder(Rational, Rational)
Remainders the specified dividend.
Declaration
public static Rational Remainder(Rational dividend, Rational divisor)
Parameters
Type |
Name |
Description |
Rational |
dividend |
The dividend.
|
Rational |
divisor |
The divisor.
|
Returns
Subtracts the specified x.
Declaration
public static Rational Subtract(Rational x, Rational y)
Parameters
Returns
Declaration
public string ToDualString()
Returns
Type |
Description |
System.String |
|
Declaration
public override string ToString()
Returns
Type |
Description |
System.String |
A System.String that represents this instance.
|
Overrides
System.ValueType.ToString()
Declaration
public static bool TryParse(string value, out Rational result, string delimiter = "/")
Parameters
Type |
Name |
Description |
System.String |
value |
|
Rational |
result |
|
System.String |
delimiter |
|
Returns
Type |
Description |
System.Boolean |
|
Declaration
public static bool TryParse(string value, NumberStyles style, IFormatProvider provider, out Rational result, string delimiter = "/")
Parameters
Type |
Name |
Description |
System.String |
value |
|
System.Globalization.NumberStyles |
style |
|
System.IFormatProvider |
provider |
|
Rational |
result |
|
System.String |
delimiter |
|
Returns
Type |
Description |
System.Boolean |
|
Operators
Declaration
public static Rational operator +(Rational r1, Rational r2)
Parameters
Returns
Declaration
public static Rational operator --(Rational r)
Parameters
Returns
Declaration
public static Rational operator /(Rational r1, Rational r2)
Parameters
Returns
Declaration
public static bool operator ==(Rational x, Rational y)
Parameters
Returns
Type |
Description |
System.Boolean |
|
Declaration
public static explicit operator byte (Rational value)
Parameters
Returns
Type |
Description |
System.Byte |
|
Declaration
public static explicit operator decimal (Rational value)
Parameters
Returns
Type |
Description |
System.Decimal |
|
Declaration
public static explicit operator double (Rational value)
Parameters
Returns
Type |
Description |
System.Double |
|
Declaration
public static explicit operator short (Rational value)
Parameters
Returns
Type |
Description |
System.Int16 |
|
Declaration
public static explicit operator int (Rational value)
Parameters
Returns
Type |
Description |
System.Int32 |
|
Declaration
public static explicit operator long (Rational value)
Parameters
Returns
Type |
Description |
System.Int64 |
|
Declaration
public static explicit operator BigInteger(Rational value)
Parameters
Returns
Type |
Description |
System.Numerics.BigInteger |
|
Declaration
public static explicit operator sbyte (Rational value)
Parameters
Returns
Type |
Description |
System.SByte |
|
Declaration
public static explicit operator float (Rational value)
Parameters
Returns
Type |
Description |
System.Single |
|
Declaration
public static explicit operator ushort (Rational value)
Parameters
Returns
Type |
Description |
System.UInt16 |
|
Declaration
public static explicit operator uint (Rational value)
Parameters
Returns
Type |
Description |
System.UInt32 |
|
Declaration
public static explicit operator ulong (Rational value)
Parameters
Returns
Type |
Description |
System.UInt64 |
|
Declaration
public static bool operator>(Rational x, Rational y)
Parameters
Returns
Type |
Description |
System.Boolean |
|
Declaration
public static bool operator >=(Rational x, Rational y)
Parameters
Returns
Type |
Description |
System.Boolean |
|
Declaration
public static implicit operator Rational(byte value)
Parameters
Type |
Name |
Description |
System.Byte |
value |
|
Returns
Declaration
public static implicit operator Rational(decimal value)
Parameters
Type |
Name |
Description |
System.Decimal |
value |
|
Returns
Declaration
public static implicit operator Rational(double value)
Parameters
Type |
Name |
Description |
System.Double |
value |
|
Returns
Declaration
public static implicit operator Rational(short value)
Parameters
Type |
Name |
Description |
System.Int16 |
value |
|
Returns
Declaration
public static implicit operator Rational(int value)
Parameters
Type |
Name |
Description |
System.Int32 |
value |
|
Returns
Declaration
public static implicit operator Rational(long value)
Parameters
Type |
Name |
Description |
System.Int64 |
value |
|
Returns
Declaration
public static implicit operator Rational(BigInteger value)
Parameters
Type |
Name |
Description |
System.Numerics.BigInteger |
value |
|
Returns
Declaration
public static implicit operator Rational(sbyte value)
Parameters
Type |
Name |
Description |
System.SByte |
value |
|
Returns
Declaration
public static implicit operator Rational(float value)
Parameters
Type |
Name |
Description |
System.Single |
value |
|
Returns
Declaration
public static implicit operator Rational(ushort value)
Parameters
Type |
Name |
Description |
System.UInt16 |
value |
|
Returns
Declaration
public static implicit operator Rational(uint value)
Parameters
Type |
Name |
Description |
System.UInt32 |
value |
|
Returns
Declaration
public static implicit operator Rational(ulong value)
Parameters
Type |
Name |
Description |
System.UInt64 |
value |
|
Returns
Declaration
public static Rational operator ++(Rational r)
Parameters
Returns
Declaration
public static bool operator !=(Rational x, Rational y)
Parameters
Returns
Type |
Description |
System.Boolean |
|
Declaration
public static bool operator <(Rational x, Rational y)
Parameters
Returns
Type |
Description |
System.Boolean |
|
Declaration
public static bool operator <=(Rational x, Rational y)
Parameters
Returns
Type |
Description |
System.Boolean |
|
Declaration
public static Rational operator %(Rational r1, Rational r2)
Parameters
Returns
Declaration
public static Rational operator *(Rational r1, Rational r2)
Parameters
Returns
Declaration
public static Rational operator -(Rational r1, Rational r2)
Parameters
Returns
Declaration
public static Rational operator -(Rational r)
Parameters
Returns
Declaration
public static Rational operator +(Rational r)
Parameters
Returns
Explicit Interface Implementations
Declaration
int IComparable.CompareTo(object obj)
Parameters
Type |
Name |
Description |
System.Object |
obj |
|
Returns
Type |
Description |
System.Int32 |
|
Declaration
void IDeserializationCallback.OnDeserialization(object sender)
Parameters
Type |
Name |
Description |
System.Object |
sender |
|
ISerializable.GetObjectData(SerializationInfo, StreamingContext)
Declaration
[SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)]
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
Parameters
Type |
Name |
Description |
System.Runtime.Serialization.SerializationInfo |
info |
|
System.Runtime.Serialization.StreamingContext |
context |
|
Implements
System.IComparable
System.IComparable<T>
System.Runtime.Serialization.IDeserializationCallback
System.IEquatable<T>
System.Runtime.Serialization.ISerializable
Extension Methods
See Also
System.IComparable
System.IComparable
System.Runtime.Serialization.IDeserializationCallback
System.IEquatable<T>
System.Runtime.Serialization.ISerializable