Struct Rational
Represents a number that can be expressed as a fraction.
Implements
Inherited Members
Namespace: SixLabors.ImageSharp
Assembly: SixLabors.ImageSharp.dll
Syntax
public readonly struct Rational : IEquatable<Rational>Remarks
This is a very simplified implementation of a rational number designed for use with metadata only.
Constructors
| Improve this Doc View SourceRational(Double)
Initializes a new instance of the Rational struct.
Declaration
public Rational(double value)Parameters
| Type | Name | Description | 
|---|---|---|
| Double | value | The Double to create the instance from. | 
Rational(Double, Boolean)
Initializes a new instance of the Rational struct.
Declaration
public Rational(double value, bool bestPrecision)Parameters
| Type | Name | Description | 
|---|---|---|
| Double | value | The Double to create the instance from. | 
| Boolean | bestPrecision | Whether to use the best possible precision when parsing the value. | 
Rational(UInt32)
Initializes a new instance of the Rational struct.
Declaration
public Rational(uint value)Parameters
| Type | Name | Description | 
|---|---|---|
| UInt32 | value | The UInt32 to create the rational from. | 
Rational(UInt32, UInt32)
Initializes a new instance of the Rational struct.
Declaration
public Rational(uint numerator, uint denominator)Parameters
| Type | Name | Description | 
|---|---|---|
| UInt32 | numerator | The number above the line in a vulgar fraction showing how many of the parts indicated by the denominator are taken. | 
| UInt32 | denominator | The number below the line in a vulgar fraction; a divisor. | 
Rational(UInt32, UInt32, Boolean)
Initializes a new instance of the Rational struct.
Declaration
public Rational(uint numerator, uint denominator, bool simplify)Parameters
| Type | Name | Description | 
|---|---|---|
| UInt32 | numerator | The number above the line in a vulgar fraction showing how many of the parts indicated by the denominator are taken. | 
| UInt32 | denominator | The number below the line in a vulgar fraction; a divisor. | 
| Boolean | simplify | Specified if the rational should be simplified. | 
Properties
| Improve this Doc View SourceDenominator
Gets the denominator of a number.
Declaration
public readonly uint Denominator { get; }Property Value
| Type | Description | 
|---|---|
| UInt32 | 
Numerator
Gets the numerator of a number.
Declaration
public readonly uint Numerator { get; }Property Value
| Type | Description | 
|---|---|
| UInt32 | 
Methods
| Improve this Doc View SourceEquals(Rational)
Declaration
public readonly bool Equals(Rational other)Parameters
| Type | Name | Description | 
|---|---|---|
| Rational | other | 
Returns
| Type | Description | 
|---|---|
| Boolean | 
Equals(Object)
Declaration
public override readonly bool Equals(object obj)Parameters
| Type | Name | Description | 
|---|---|---|
| Object | obj | 
Returns
| Type | Description | 
|---|---|
| Boolean | 
Overrides
| Improve this Doc View SourceFromDouble(Double)
Converts the specified Double to an instance of this type.
Declaration
public static Rational FromDouble(double value)Parameters
| Type | Name | Description | 
|---|---|---|
| Double | value | The Double to convert to an instance of this type. | 
Returns
| Type | Description | 
|---|---|
| Rational | The Rational. | 
FromDouble(Double, Boolean)
Converts the specified Double to an instance of this type.
Declaration
public static Rational FromDouble(double value, bool bestPrecision)Parameters
| Type | Name | Description | 
|---|---|---|
| Double | value | The Double to convert to an instance of this type. | 
| Boolean | bestPrecision | Whether to use the best possible precision when parsing the value. | 
Returns
| Type | Description | 
|---|---|
| Rational | The Rational. | 
GetHashCode()
Declaration
public override readonly int GetHashCode()Returns
| Type | Description | 
|---|---|
| Int32 | 
Overrides
| Improve this Doc View SourceToDouble()
Converts a rational number to the nearest Double.
Declaration
public readonly double ToDouble()Returns
| Type | Description | 
|---|---|
| Double | The Double. | 
ToSingle()
Converts a rational number to the nearest Single.
Declaration
public readonly float ToSingle()Returns
| Type | Description | 
|---|---|
| Single | The Single. | 
ToString()
Declaration
public override readonly string ToString()Returns
| Type | Description | 
|---|---|
| String | 
Overrides
| Improve this Doc View SourceToString(IFormatProvider)
Converts the numeric value of this instance to its equivalent string representation using the specified culture-specific format information.
Declaration
public readonly string ToString(IFormatProvider provider)Parameters
| Type | Name | Description | 
|---|---|---|
| IFormatProvider | provider | An object that supplies culture-specific formatting information. | 
Returns
| Type | Description | 
|---|---|
| String | The String | 
Operators
| Improve this Doc View SourceEquality(Rational, Rational)
Determines whether the specified Rational instances are considered equal.
Declaration
public static bool operator ==(Rational left, Rational right)Parameters
| Type | Name | Description | 
|---|---|---|
| Rational | left | The first Rational to compare. | 
| Rational | right | The second Rational to compare. | 
Returns
| Type | Description | 
|---|---|
| Boolean | The Boolean | 
Inequality(Rational, Rational)
Determines whether the specified Rational instances are not considered equal.
Declaration
public static bool operator !=(Rational left, Rational right)Parameters
| Type | Name | Description | 
|---|---|---|
| Rational | left | The first Rational to compare. | 
| Rational | right | The second Rational to compare. | 
Returns
| Type | Description | 
|---|---|
| Boolean | The Boolean |