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)

public bool Equals(Rational other)

Parameters

other Rational

Returns

bool

Equals(object?)

public override bool Equals(object? obj)

Parameters

obj object

Returns

bool

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()

public override int GetHashCode()

Returns

int

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()

public override string ToString()

Returns

string

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