Struct Rational
- Namespace
- SixLabors.ImageSharp
- Assembly
- SixLabors.ImageSharp.dll
Represents a number that can be expressed as a fraction.
public readonly struct Rational : IEquatable<Rational>
- Implements
- Inherited Members
Remarks
This is a very simplified implementation of a rational number designed for use with metadata only.
Constructors
Rational(double)
Initializes a new instance of the Rational struct.
public Rational(double value)
Parameters
Rational(double, bool)
Initializes a new instance of the Rational struct.
public Rational(double value, bool bestPrecision)
Parameters
value
doubleThe double to create the instance from.
bestPrecision
boolWhether to use the best possible precision when parsing the value.
Rational(uint)
Initializes a new instance of the Rational struct.
public Rational(uint value)
Parameters
Rational(uint, uint)
Initializes a new instance of the Rational struct.
public Rational(uint numerator, uint denominator)
Parameters
numerator
uintThe number above the line in a vulgar fraction showing how many of the parts indicated by the denominator are taken.
denominator
uintThe number below the line in a vulgar fraction; a divisor.
Rational(uint, uint, bool)
Initializes a new instance of the Rational struct.
public Rational(uint numerator, uint denominator, bool simplify)
Parameters
numerator
uintThe number above the line in a vulgar fraction showing how many of the parts indicated by the denominator are taken.
denominator
uintThe number below the line in a vulgar fraction; a divisor.
simplify
boolSpecified if the rational should be simplified.
Properties
Denominator
Gets the denominator of a number.
public uint Denominator { get; }
Property Value
Numerator
Gets the numerator of a number.
public uint Numerator { get; }
Property Value
Methods
Equals(Rational)
public bool Equals(Rational other)
Parameters
other
Rational
Returns
Equals(object?)
public override bool Equals(object? obj)
Parameters
obj
object
Returns
FromDouble(double)
Converts the specified double to an instance of this type.
public static Rational FromDouble(double value)
Parameters
Returns
FromDouble(double, bool)
Converts the specified double to an instance of this type.
public static Rational FromDouble(double value, bool bestPrecision)
Parameters
value
doubleThe double to convert to an instance of this type.
bestPrecision
boolWhether to use the best possible precision when parsing the value.
Returns
GetHashCode()
public override int GetHashCode()
Returns
ToDouble()
Converts a rational number to the nearest double.
public double ToDouble()
Returns
ToSingle()
Converts a rational number to the nearest float.
public float ToSingle()
Returns
ToString()
public override string ToString()
Returns
ToString(IFormatProvider)
Converts the numeric value of this instance to its equivalent string representation using the specified culture-specific format information.
public string ToString(IFormatProvider provider)
Parameters
provider
IFormatProviderAn object that supplies culture-specific formatting information.
Returns
Operators
operator ==(Rational, Rational)
Determines whether the specified Rational instances are considered equal.
public static bool operator ==(Rational left, Rational right)
Parameters
Returns
operator !=(Rational, Rational)
Determines whether the specified Rational instances are not considered equal.
public static bool operator !=(Rational left, Rational right)