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
valuedoubleThe double to create the instance from.
bestPrecisionboolWhether 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
numeratoruintThe number above the line in a vulgar fraction showing how many of the parts indicated by the denominator are taken.
denominatoruintThe 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
numeratoruintThe number above the line in a vulgar fraction showing how many of the parts indicated by the denominator are taken.
denominatoruintThe number below the line in a vulgar fraction; a divisor.
simplifyboolSpecified 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)
Indicates whether the current object is equal to another object of the same type.
public bool Equals(Rational other)
Parameters
otherRationalAn object to compare with this object.
Returns
Equals(object?)
Indicates whether this instance and a specified object are equal.
public override bool Equals(object? obj)
Parameters
objobjectThe object to compare with the current instance.
Returns
- bool
true if
objand this instance are the same type and represent the same value; otherwise, false.
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
valuedoubleThe double to convert to an instance of this type.
bestPrecisionboolWhether to use the best possible precision when parsing the value.
Returns
GetHashCode()
Returns the hash code for this instance.
public override int GetHashCode()
Returns
- int
A 32-bit signed integer that is the hash code for this instance.
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()
Returns the fully qualified type name of this instance.
public override string ToString()
Returns
- string
The fully qualified type name.
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
providerIFormatProviderAn 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)