Struct RationalValue
- Namespace
- xFunc.Maths.Expressions
- Assembly
- xFunc.Maths.dll
Represents the rational number.
public readonly struct RationalValue : IEquatable<RationalValue>, IComparable<RationalValue>, IComparable
- Implements
- Inherited Members
Constructors
RationalValue(double, double)
Initializes a new instance of the RationalValue struct.
public RationalValue(double numerator, double denominator)
Parameters
RationalValue(NumberValue, NumberValue)
Initializes a new instance of the RationalValue struct.
public RationalValue(NumberValue numerator, NumberValue denominator)
Parameters
numeratorNumberValueThe numerator.
denominatorNumberValueThe denominator.
Properties
Denominator
Gets the denominator.
public NumberValue Denominator { get; }
Property Value
Numerator
Gets the numerator.
public NumberValue Numerator { get; }
Property Value
Methods
Abs(RationalValue)
Returns the absolute value of a rational number.
public static RationalValue Abs(RationalValue rationalValue)
Parameters
rationalValueRationalValueThe rational number.
Returns
- RationalValue
The abs of rational number.
CompareTo(object?)
Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.
public int CompareTo(object? obj)
Parameters
objobjectAn object to compare with this instance.
Returns
- int
A value that indicates the relative order of the objects being compared. The return value has these meanings:
Value Meaning Less than zero This instance precedes objin the sort order.Zero This instance occurs in the same position in the sort order as obj.Greater than zero This instance follows objin the sort order.
Exceptions
- ArgumentException
objis not the same type as this instance.
CompareTo(RationalValue)
Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.
public int CompareTo(RationalValue other)
Parameters
otherRationalValueAn object to compare with this instance.
Returns
- int
A value that indicates the relative order of the objects being compared. The return value has these meanings:
Value Meaning Less than zero This instance precedes otherin the sort order.Zero This instance occurs in the same position in the sort order as other.Greater than zero This instance follows otherin the sort order.
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.
Equals(RationalValue)
Indicates whether the current object is equal to another object of the same type.
public bool Equals(RationalValue other)
Parameters
otherRationalValueAn object to compare with this object.
Returns
GetHashCode()
Returns the hash code for this instance.
[ExcludeFromCodeCoverage]
public override int GetHashCode()
Returns
- int
A 32-bit signed integer that is the hash code for this instance.
Lb(RationalValue)
Returns the base 2 logarithm of a specified rational number.
public static NumberValue Lb(RationalValue rationalValue)
Parameters
rationalValueRationalValueA rational number whose logarithm is to be found.
Returns
- NumberValue
The binary logarithm.
Lg(RationalValue)
Returns the base 10 logarithm of a specified rational number.
public static NumberValue Lg(RationalValue rationalValue)
Parameters
rationalValueRationalValueA rational number whose logarithm is to be found.
Returns
- NumberValue
The base 10 logarithm.
Ln(RationalValue)
Returns the natural (base e) logarithm of a specified rational number.
public static NumberValue Ln(RationalValue rationalValue)
Parameters
rationalValueRationalValueThe rational number whose logarithm is to be found.
Returns
- NumberValue
The natural (base
e) logarithm.
Log(RationalValue, NumberValue)
Returns the logarithm of a specified number in a specified base.
public static NumberValue Log(RationalValue rationalValue, NumberValue @base)
Parameters
rationalValueRationalValueThe rational number whose logarithm is to be found.
baseNumberValueThe base of the logarithm.
Returns
- NumberValue
The logarithm.
Pow(RationalValue, NumberValue)
Returns the rational number raised to the specified power.
public static RationalValue Pow(RationalValue rationalValue, NumberValue numberValue)
Parameters
rationalValueRationalValueThe rational number.
numberValueNumberValueThe power.
Returns
- RationalValue
The
rationalValueraised to thenumberValue.
ToCanonical()
Converts the current rational number to the canonical form.
public RationalValue ToCanonical()
Returns
- RationalValue
The rational number in the canonical form.
ToIrrational()
Converts the current rational number to irrational.
public NumberValue ToIrrational()
Returns
- NumberValue
The irrational number.
ToString()
Returns the fully qualified type name of this instance.
public override string ToString()
Returns
- string
The fully qualified type name.
Operators
operator +(NumberValue, RationalValue)
Adds double and RationalValue.
public static RationalValue operator +(NumberValue left, RationalValue right)
Parameters
leftNumberValueThe first object to add.
rightRationalValueThe second object to add.
Returns
- RationalValue
An object that is the sum of
leftandright.
operator +(RationalValue, NumberValue)
Adds RationalValue and double.
public static RationalValue operator +(RationalValue left, NumberValue right)
Parameters
leftRationalValueThe first object to add.
rightNumberValueThe second object to add.
Returns
- RationalValue
An object that is the sum of
leftandright.
operator +(RationalValue, RationalValue)
Adds two objects of RationalValue.
public static RationalValue operator +(RationalValue left, RationalValue right)
Parameters
leftRationalValueThe first object to add.
rightRationalValueThe second object to add.
Returns
- RationalValue
An object that is the sum of
leftandright.
operator /(NumberValue, RationalValue)
Divides double and RationalValue.
public static RationalValue operator /(NumberValue left, RationalValue right)
Parameters
leftNumberValueThe first object to divide.
rightRationalValueThe second object to divide.
Returns
- RationalValue
An object that is the fraction of
leftandright.
operator /(RationalValue, NumberValue)
Divides RationalValue and double.
public static RationalValue operator /(RationalValue left, NumberValue right)
Parameters
leftRationalValueThe first object to divide.
rightNumberValueThe second object to divide.
Returns
- RationalValue
An object that is the fraction of
leftandright.
operator /(RationalValue, RationalValue)
Divides two objects of RationalValue.
public static RationalValue operator /(RationalValue left, RationalValue right)
Parameters
leftRationalValueThe first object to divide.
rightRationalValueThe second object to divide.
Returns
- RationalValue
An object that is the fraction of
leftandright.
operator ==(RationalValue, RationalValue)
Determines whether two specified instances of RationalValue are equal.
public static bool operator ==(RationalValue left, RationalValue right)
Parameters
leftRationalValueThe first object to compare.
rightRationalValueThe second object to compare.
Returns
- bool
trueifleftis equal toright; otherwise,false.
operator >(RationalValue, RationalValue)
Indicates whether left parameter is greater than the right parameter.
public static bool operator >(RationalValue left, RationalValue right)
Parameters
leftRationalValueThe first object to compare.
rightRationalValueThe second object to compare.
Returns
- bool
trueif theleftparameter is greater than therightparameter; otherwise,false.
operator >=(RationalValue, RationalValue)
Indicates whether left parameter is greater than or equal to the right parameter.
public static bool operator >=(RationalValue left, RationalValue right)
Parameters
leftRationalValueThe first object to compare.
rightRationalValueThe second object to compare.
Returns
- bool
trueif theleftparameter is greater than or equal to therightparameter; otherwise,false.
operator !=(RationalValue, RationalValue)
Determines whether two specified instances of RationalValue are not equal.
public static bool operator !=(RationalValue left, RationalValue right)
Parameters
leftRationalValueThe first object to compare.
rightRationalValueThe second object to compare.
Returns
- bool
trueifleftis not equal toright; otherwise,false.
operator <(RationalValue, RationalValue)
Indicates whether left parameter is less than the right parameter.
public static bool operator <(RationalValue left, RationalValue right)
Parameters
leftRationalValueThe first object to compare.
rightRationalValueThe second object to compare.
Returns
- bool
trueif theleftparameter is less than therightparameter; otherwise,false.
operator <=(RationalValue, RationalValue)
Indicates whether left parameter is less than or equal to the right parameter.
public static bool operator <=(RationalValue left, RationalValue right)
Parameters
leftRationalValueThe first object to compare.
rightRationalValueThe second object to compare.
Returns
- bool
trueif theleftparameter is less than or equal to therightparameter; otherwise,false.
operator *(NumberValue, RationalValue)
Multiplies double and RationalValue.
public static RationalValue operator *(NumberValue left, RationalValue right)
Parameters
leftNumberValueThe first object to multiply.
rightRationalValueThe second object to multiply.
Returns
- RationalValue
An object that is the product of
leftandright.
operator *(RationalValue, NumberValue)
Multiplies RationalValue and double.
public static RationalValue operator *(RationalValue left, NumberValue right)
Parameters
leftRationalValueThe first object to multiply.
rightNumberValueThe second object to multiply.
Returns
- RationalValue
An object that is the product of
leftandright.
operator *(RationalValue, RationalValue)
Multiplies two objects of RationalValue.
public static RationalValue operator *(RationalValue left, RationalValue right)
Parameters
leftRationalValueThe first object to multiply.
rightRationalValueThe second object to multiply.
Returns
- RationalValue
An object that is the product of
leftandright.
operator -(NumberValue, RationalValue)
Subtracts double and RationalValue.
public static RationalValue operator -(NumberValue left, RationalValue right)
Parameters
leftNumberValueThe first object to sub.
rightRationalValueThe second object to sub.
Returns
- RationalValue
An object that is the difference of
leftandright.
operator -(RationalValue, NumberValue)
Subtracts RationalValue and double.
public static RationalValue operator -(RationalValue left, NumberValue right)
Parameters
leftRationalValueThe first object to sub.
rightNumberValueThe second object to sub.
Returns
- RationalValue
An object that is the difference of
leftandright.
operator -(RationalValue, RationalValue)
Subtracts two objects of RationalValue.
public static RationalValue operator -(RationalValue left, RationalValue right)
Parameters
leftRationalValueThe first object to sub.
rightRationalValueThe second object to sub.
Returns
- RationalValue
An object that is the difference of
leftandright.
operator -(RationalValue)
Produces the negative of RationalValue.
public static RationalValue operator -(RationalValue rationalValue)
Parameters
rationalValueRationalValueThe rational number.
Returns
- RationalValue
The negative of
rationalValue.