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
| Edit this page 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, bool)
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. |
bool | bestPrecision | Whether to use the best possible precision when parsing the value. |
Rational(uint)
Initializes a new instance of the Rational struct.
Declaration
public Rational(uint value)
Parameters
Type | Name | Description |
---|---|---|
uint | value | The uint to create the rational from. |
Rational(uint, uint)
Initializes a new instance of the Rational struct.
Declaration
public Rational(uint numerator, uint denominator)
Parameters
Type | Name | Description |
---|---|---|
uint | numerator | The number above the line in a vulgar fraction showing how many of the parts indicated by the denominator are taken. |
uint | denominator | The number below the line in a vulgar fraction; a divisor. |
Rational(uint, uint, bool)
Initializes a new instance of the Rational struct.
Declaration
public Rational(uint numerator, uint denominator, bool simplify)
Parameters
Type | Name | Description |
---|---|---|
uint | numerator | The number above the line in a vulgar fraction showing how many of the parts indicated by the denominator are taken. |
uint | denominator | The number below the line in a vulgar fraction; a divisor. |
bool | simplify | Specified if the rational should be simplified. |
Properties
| Edit this page View SourceDenominator
Gets the denominator of a number.
Declaration
public uint Denominator { get; }
Property Value
Type | Description |
---|---|
uint |
Numerator
Gets the numerator of a number.
Declaration
public uint Numerator { get; }
Property Value
Type | Description |
---|---|
uint |
Methods
| Edit this page View SourceEquals(Rational)
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 |
---|---|
bool | true if the current object is equal to the |
Equals(object?)
Indicates whether this instance and a specified object are equal.
Declaration
public override bool Equals(object? obj)
Parameters
Type | Name | Description |
---|---|---|
object | obj | The object to compare with the current instance. |
Returns
Type | Description |
---|---|
bool | true if |
Overrides
| Edit this page 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, bool)
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. |
bool | bestPrecision | Whether to use the best possible precision when parsing the value. |
Returns
Type | Description |
---|---|
Rational | The Rational. |
GetHashCode()
Returns the hash code for this instance.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
int | A 32-bit signed integer that is the hash code for this instance. |
Overrides
| Edit this page View SourceToDouble()
Converts a rational number to the nearest double.
Declaration
public double ToDouble()
Returns
Type | Description |
---|---|
double | The double. |
ToSingle()
Converts a rational number to the nearest float.
Declaration
public float ToSingle()
Returns
Type | Description |
---|---|
float | The float. |
ToString()
Returns the fully qualified type name of this instance.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
string | The fully qualified type name. |
Overrides
| Edit this page View SourceToString(IFormatProvider)
Converts the numeric value of this instance to its equivalent string representation using the specified culture-specific format information.
Declaration
public 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
| Edit this page View Sourceoperator ==(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 |
---|---|
bool | The bool |
operator !=(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 |
---|---|
bool | The bool |