Table of Contents

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

value double

The double to create the instance from.

Rational(double, bool)

Initializes a new instance of the Rational struct.

public Rational(double value, bool bestPrecision)

Parameters

value double

The double to create the instance from.

bestPrecision bool

Whether 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

value uint

The uint to create the rational from.

Rational(uint, uint)

Initializes a new instance of the Rational struct.

public Rational(uint numerator, uint denominator)

Parameters

numerator uint

The number above the line in a vulgar fraction showing how many of the parts indicated by the denominator are taken.

denominator uint

The 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 uint

The number above the line in a vulgar fraction showing how many of the parts indicated by the denominator are taken.

denominator uint

The number below the line in a vulgar fraction; a divisor.

simplify bool

Specified if the rational should be simplified.

Properties

Denominator

Gets the denominator of a number.

public uint Denominator { get; }

Property Value

uint

Numerator

Gets the numerator of a number.

public uint Numerator { get; }

Property Value

uint

Methods

Equals(Rational)

Indicates whether the current object is equal to another object of the same type.

public bool Equals(Rational other)

Parameters

other Rational

An object to compare with this object.

Returns

bool

true if the current object is equal to the other parameter; otherwise, false.

Equals(object?)

Indicates whether this instance and a specified object are equal.

public override bool Equals(object? obj)

Parameters

obj object

The object to compare with the current instance.

Returns

bool

true if obj and 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

value double

The double to convert to an instance of this type.

Returns

Rational

The Rational.

FromDouble(double, bool)

Converts the specified double to an instance of this type.

public static Rational FromDouble(double value, bool bestPrecision)

Parameters

value double

The double to convert to an instance of this type.

bestPrecision bool

Whether to use the best possible precision when parsing the value.

Returns

Rational

The Rational.

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

double

The double.

ToSingle()

Converts a rational number to the nearest float.

public float ToSingle()

Returns

float

The float.

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

provider IFormatProvider

An object that supplies culture-specific formatting information.

Returns

string

The string

Operators

operator ==(Rational, Rational)

Determines whether the specified Rational instances are considered equal.

public static bool operator ==(Rational left, Rational right)

Parameters

left Rational

The first Rational to compare.

right Rational

The second Rational to compare.

Returns

bool

The bool

operator !=(Rational, Rational)

Determines whether the specified Rational instances are not considered equal.

public static bool operator !=(Rational left, Rational right)

Parameters

left Rational

The first Rational to compare.

right Rational

The second Rational to compare.

Returns

bool

The bool