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
numerator
NumberValueThe numerator.
denominator
NumberValueThe 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
rationalValue
RationalValueThe 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
obj
objectAn 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 obj
in the sort order.Zero This instance occurs in the same position in the sort order as obj
.Greater than zero This instance follows obj
in the sort order.
Exceptions
- ArgumentException
obj
is 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
other
RationalValueAn 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 other
in the sort order.Zero This instance occurs in the same position in the sort order as other
.Greater than zero This instance follows other
in the sort order.
Equals(object?)
Indicates whether this instance and a specified object are equal.
public override bool Equals(object? obj)
Parameters
obj
objectThe 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.
Equals(RationalValue)
Indicates whether the current object is equal to another object of the same type.
public bool Equals(RationalValue other)
Parameters
other
RationalValueAn object to compare with this object.
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.
Lb(RationalValue)
Returns the base 2 logarithm of a specified rational number.
public static NumberValue Lb(RationalValue rationalValue)
Parameters
rationalValue
RationalValueA 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
rationalValue
RationalValueA 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
rationalValue
RationalValueThe 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
rationalValue
RationalValueThe rational number whose logarithm is to be found.
base
NumberValueThe 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
rationalValue
RationalValueThe rational number.
numberValue
NumberValueThe power.
Returns
- RationalValue
The
rationalValue
raised 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
left
NumberValueThe first object to add.
right
RationalValueThe second object to add.
Returns
- RationalValue
An object that is the sum of
left
andright
.
operator +(RationalValue, NumberValue)
Adds RationalValue and double.
public static RationalValue operator +(RationalValue left, NumberValue right)
Parameters
left
RationalValueThe first object to add.
right
NumberValueThe second object to add.
Returns
- RationalValue
An object that is the sum of
left
andright
.
operator +(RationalValue, RationalValue)
Adds two objects of RationalValue.
public static RationalValue operator +(RationalValue left, RationalValue right)
Parameters
left
RationalValueThe first object to add.
right
RationalValueThe second object to add.
Returns
- RationalValue
An object that is the sum of
left
andright
.
operator /(NumberValue, RationalValue)
Divides double and RationalValue.
public static RationalValue operator /(NumberValue left, RationalValue right)
Parameters
left
NumberValueThe first object to divide.
right
RationalValueThe second object to divide.
Returns
- RationalValue
An object that is the fraction of
left
andright
.
operator /(RationalValue, NumberValue)
Divides RationalValue and double.
public static RationalValue operator /(RationalValue left, NumberValue right)
Parameters
left
RationalValueThe first object to divide.
right
NumberValueThe second object to divide.
Returns
- RationalValue
An object that is the fraction of
left
andright
.
operator /(RationalValue, RationalValue)
Divides two objects of RationalValue.
public static RationalValue operator /(RationalValue left, RationalValue right)
Parameters
left
RationalValueThe first object to divide.
right
RationalValueThe second object to divide.
Returns
- RationalValue
An object that is the fraction of
left
andright
.
operator ==(RationalValue, RationalValue)
Determines whether two specified instances of RationalValue are equal.
public static bool operator ==(RationalValue left, RationalValue right)
Parameters
left
RationalValueThe first object to compare.
right
RationalValueThe second object to compare.
Returns
- bool
true
ifleft
is 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
left
RationalValueThe first object to compare.
right
RationalValueThe second object to compare.
Returns
- bool
true
if theleft
parameter is greater than theright
parameter; 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
left
RationalValueThe first object to compare.
right
RationalValueThe second object to compare.
Returns
- bool
true
if theleft
parameter is greater than or equal to theright
parameter; otherwise,false
.
operator !=(RationalValue, RationalValue)
Determines whether two specified instances of RationalValue are not equal.
public static bool operator !=(RationalValue left, RationalValue right)
Parameters
left
RationalValueThe first object to compare.
right
RationalValueThe second object to compare.
Returns
- bool
true
ifleft
is 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
left
RationalValueThe first object to compare.
right
RationalValueThe second object to compare.
Returns
- bool
true
if theleft
parameter is less than theright
parameter; 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
left
RationalValueThe first object to compare.
right
RationalValueThe second object to compare.
Returns
- bool
true
if theleft
parameter is less than or equal to theright
parameter; otherwise,false
.
operator *(NumberValue, RationalValue)
Multiplies double and RationalValue.
public static RationalValue operator *(NumberValue left, RationalValue right)
Parameters
left
NumberValueThe first object to multiply.
right
RationalValueThe second object to multiply.
Returns
- RationalValue
An object that is the product of
left
andright
.
operator *(RationalValue, NumberValue)
Multiplies RationalValue and double.
public static RationalValue operator *(RationalValue left, NumberValue right)
Parameters
left
RationalValueThe first object to multiply.
right
NumberValueThe second object to multiply.
Returns
- RationalValue
An object that is the product of
left
andright
.
operator *(RationalValue, RationalValue)
Multiplies two objects of RationalValue.
public static RationalValue operator *(RationalValue left, RationalValue right)
Parameters
left
RationalValueThe first object to multiply.
right
RationalValueThe second object to multiply.
Returns
- RationalValue
An object that is the product of
left
andright
.
operator -(NumberValue, RationalValue)
Subtracts double and RationalValue.
public static RationalValue operator -(NumberValue left, RationalValue right)
Parameters
left
NumberValueThe first object to sub.
right
RationalValueThe second object to sub.
Returns
- RationalValue
An object that is the difference of
left
andright
.
operator -(RationalValue, NumberValue)
Subtracts RationalValue and double.
public static RationalValue operator -(RationalValue left, NumberValue right)
Parameters
left
RationalValueThe first object to sub.
right
NumberValueThe second object to sub.
Returns
- RationalValue
An object that is the difference of
left
andright
.
operator -(RationalValue, RationalValue)
Subtracts two objects of RationalValue.
public static RationalValue operator -(RationalValue left, RationalValue right)
Parameters
left
RationalValueThe first object to sub.
right
RationalValueThe second object to sub.
Returns
- RationalValue
An object that is the difference of
left
andright
.
operator -(RationalValue)
Produces the negative of RationalValue.
public static RationalValue operator -(RationalValue rationalValue)
Parameters
rationalValue
RationalValueThe rational number.
Returns
- RationalValue
The negative of
rationalValue
.