Class Q
Represents the set of rational numbers, denoted by ℚ in mathematics.
Inherited Members
Namespace: MathLib
Assembly: MathLib.dll
Syntax
public class Q : IEquatable<Q>, IComparable<Q>
Remarks
The set of rational numbers is defined as the set of all numbers that can be expressed as the quotient of two integers, where the denominator is non-zero. Formally:
ℚ = {a / b | a ∈ ℤ, b ∈ ℤ, b ≠ 0}
Rational numbers include integers, fractions, and terminating or repeating decimal expansions. Many operations, such as addition, subtraction, multiplication, and division (excluding division by zero) are closed within ℚ.Rational numbers can be embedded within the set of real numbers ℝ, and the set of p-adic numbers ℚₚ. They serve as the foundation for more complex number systems.
In this library, the class Q represents the mathematical structure of rational numbers, and serves as a base for more advanced number fields like Qp and Cp.
The class methods must never throw exceptions from arithmetic operations. Instead, they return NaN for undefined results (such as from divide by zero).
Constructors
| Edit this page View SourceQ()
Initializes a rational number for the default value zero.
Declaration
public Q()
Q(Q)
Protected constructor that creates a copy of a Q object.
Declaration
protected Q(Q q)
Parameters
Type | Name | Description |
---|---|---|
Q | q |
Q(BigInteger)
Initializes a rational number with the specified integer value.
Declaration
public Q(BigInteger numerator)
Parameters
Type | Name | Description |
---|---|---|
BigInteger | numerator | The integer value. |
Q(BigInteger, BigInteger)
Initializes a rational number with the specified numerator and denominator.
The rational number is automatically normalized
, meaning:
Q will be simplified so the numerator and denominator is coprime.
The sign of the number will always be carried by the numerator (denominator will be strictly positive).
Declaration
public Q(BigInteger numerator, BigInteger denominator)
Parameters
Type | Name | Description |
---|---|---|
BigInteger | numerator | The numerator of the rational number. |
BigInteger | denominator | The denominator of the rational number. |
Q(BigInteger, BigInteger, bool)
Protected constructor for a rational number with the specified numerator and denominator.
Declaration
public Q(BigInteger numerator, BigInteger denominator, bool normalize)
Parameters
Type | Name | Description |
---|---|---|
BigInteger | numerator | The numerator of the rational number. |
BigInteger | denominator | The denominator of the rational number. |
bool | normalize |
|
Remarks
Caution: Setting normalize
to false will result in a faulty object if any of the following conditions are not met:
- The
numerator
anddenominator
are coprime (i.e., their greatest common divisor is 1). - The
denominator
is greater than0
.
If unsure if above conditions hold, use the public constructor Q(BigInteger, BigInteger) instead.
If you are sure above conditions hold, you can safely set normalize
to false for significantly faster execution.
Properties
| Edit this page View SourceAbs
Gets the absolute value of the current rational number.
Declaration
public Q Abs { get; }
Property Value
Type | Description |
---|---|
Q | A Q representing the absolute value of the current rational number. If the rational number is negative, a new Q instance is returned with the absolute value. If the rational number is non-negative, the current instance is returned. |
Denominator
The denominator of the rational number, guaranteed to be positive in normalized form.
Declaration
public BigInteger Denominator { get; }
Property Value
Type | Description |
---|---|
BigInteger |
FractionalPart
Declaration
public Q FractionalPart { get; }
Property Value
Type | Description |
---|---|
Q | The fractional part of the rational number, obtained by subtracting the integer part. |
IntegralPart
The integral (integer) part of a rational number
Declaration
public BigInteger IntegralPart { get; }
Property Value
Type | Description |
---|---|
BigInteger |
Remarks
In general mathematics, the concept of "integral part" is not objectively defined, since it has two possible interpretations (or modes). These interpretations are defined by whether we regard the set of all pure fractions to include the number 1 or not. We denote these interpretations (modes) as FEO (Fractions Exclude One) and FIO (Fractions Include One), respectively.
For instance, in decimal, the number 1 could have the following two interpretations:
1 = 1.000000... (FEO)
1 = 0.999999... (FIO)
In FEO the number 1 is a purely integral number, with integral part=1 and fractional part=0.
In FIO the number 1 is a purely fractional number, with integral part=0 and fractional part=1.
Irrespective of the mode, any number is always the sum of its integral and fractional parts.
In FIO, all numbers will have a non-zero-terminating expansion.
In FEO, any number that can terminate (with an ultimately infinite expansion of zeros) will do so.
Only numbers with a period of 0, can have different representations in FIO and FEO.
To make IntegralPart and FractionalPart well defined, yet allow access to both FIO and FEO, we assign FEO to all positive numbers, and FIO to all negative numbers and zero. This will make all members of Q have only one correct expansion.
This whole logic is completely governed by the implementation of IntegralPart. Hence, we do not need to manage modes anywhere in the code base.
To instead swap behavior (positive numbers = FIO and negative numbers = FEO) we can change IntegralPart to the following:
public BigInteger IntegralPart =>
IsPositiveInteger
? (Numerator / Denominator) - 1
: (Numerator / Denominator);
Examples
Q | Expansion | Mode |
---|---|---|
0 | .0000000000000000 | FEO=FIO, in any base |
1₂ | 1.000000000000000 | FEO |
-1₂ | .1111111111111111 | FIO |
103/16₂ | 110.0111000000000 | FEO |
-103/16₂ | 110.0110111111111 | FIO |
5/24₂ | .0011010101010101 | FEO=FIO |
-5/24₂ | .0011010101010101 | FEO=FIO |
3/45₅ | .3333333333333333 | FEO=FIO |
-3/45₅ | .3333333333333333 | FEO=FIO |
537/11₃ | 1210.211002110021 | FEO=FIO |
-537/11₃ | 1210.211002110021 | FEO=FIO |
See Also
| Edit this page View SourceIntegralPartAlwaysFEO
This version always sets FEO mode.
Declaration
protected BigInteger IntegralPartAlwaysFEO { get; }
Property Value
Type | Description |
---|---|
BigInteger |
IsInteger
Indicates whether the rational number is an integer.
Declaration
public bool IsInteger { get; }
Property Value
Type | Description |
---|---|
bool |
IsNaN
Indicates whether the rational number is NaN (not a number), indicated by a zero denominator.
Declaration
public bool IsNaN { get; }
Property Value
Type | Description |
---|---|
bool |
IsNegative
Indicates whether the rational number is negative.
Declaration
public bool IsNegative { get; }
Property Value
Type | Description |
---|---|
bool |
IsNegativeInteger
Indicates whether the rational number is a negative integer.
Declaration
public bool IsNegativeInteger { get; }
Property Value
Type | Description |
---|---|
bool |
IsNonZeroInteger
Indicates whether the rational number is a non-zero integer.
Declaration
public bool IsNonZeroInteger { get; }
Property Value
Type | Description |
---|---|
bool |
IsOne
Indicates whether the rational number is equal to one.
Declaration
public bool IsOne { get; }
Property Value
Type | Description |
---|---|
bool |
IsPositive
Indicates whether the rational number is positive.
Declaration
public bool IsPositive { get; }
Property Value
Type | Description |
---|---|
bool |
IsPositiveInteger
Indicates whether the rational number is a positive integer.
Declaration
public bool IsPositiveInteger { get; }
Property Value
Type | Description |
---|---|
bool |
IsUnitFraction
Indicates whether the rational number is a unit fraction.
Declaration
public bool IsUnitFraction { get; }
Property Value
Type | Description |
---|---|
bool |
Remarks
Unit fractions are strictly positive, meaning -1/10
is not a unit fraction.
IsZero
Indicates whether the rational number is zero.
Declaration
public bool IsZero { get; }
Property Value
Type | Description |
---|---|
bool |
NaN
Declaration
public static Q NaN { get; }
Property Value
Type | Description |
---|---|
Q | Represents a NaN (not a number) denoting an invalid number. NaN is return value of operations that are not defined (e.g. when dividing by zero) |
Numerator
The numerator of the rational number.
Declaration
public BigInteger Numerator { get; }
Property Value
Type | Description |
---|---|
BigInteger |
One
Declaration
public static Q One { get; }
Property Value
Type | Description |
---|---|
Q | Represents the rational number one. |
Reciprocal
Reciprocal of this rational number.
Declaration
public Q Reciprocal { get; }
Property Value
Type | Description |
---|---|
Q |
Remarks
The reciprocal of a rational number a/b
is b/a
.
Returns NaN if the numerator is 0
.
Sign
Sign of the current rational number.
Declaration
public int Sign { get; }
Property Value
Type | Description |
---|---|
int | An integer that indicates the sign of the current rational number. Returns -1 if the number is negative, 0 if the number is zero, and 1 if the number is positive. |
Zero
Declaration
public static Q Zero { get; }
Property Value
Type | Description |
---|---|
Q | Represents the rational number zero. |
Methods
| Edit this page View SourceBackward(int)
Obsolete: This method is obsolete and will be removed.
Declaration
[Obsolete("This method is obsolete and will be removed")]
public Q Backward(int base_)
Parameters
Type | Name | Description |
---|---|---|
int | base_ |
Returns
Type | Description |
---|---|
Q |
Coeff(int)
The value of the rational number in the specified base.
Declaration
public BigInteger Coeff(int base_)
Parameters
Type | Name | Description |
---|---|---|
int | base_ | The base to convert to. |
Returns
Type | Description |
---|---|
BigInteger | The coefficient of the rational number in the specified base. |
Coefficients(int)
Light version of Coefficients() that takes a rational number and a base.
Declaration
public IEnumerable<int> Coefficients(int base_)
Parameters
Type | Name | Description |
---|---|---|
int | base_ | The base to convert to. |
Returns
Type | Description |
---|---|
IEnumerable<int> | An enumerable sequence of integers representing the coefficients of the rational number in the specified base. |
Remarks
This method does not require the costly creation of a Qb.
See Also
| Edit this page View SourceCompareTo(Q?)
Compares the current rational number to another rational number.
Declaration
public int CompareTo(Q? other)
Parameters
Type | Name | Description |
---|---|---|
Q | other | The rational number to compare with. |
Returns
Type | Description |
---|---|
int | An integer that indicates the relative order of the current rational number and the specified rational number. |
CompareTo(int)
Compares the current rational number to an int.
Declaration
public int CompareTo(int integer)
Parameters
Type | Name | Description |
---|---|---|
int | integer | The int to compare with. |
Returns
Type | Description |
---|---|
int | An integer that indicates the relative order of the current rational number and |
CompareTo(BigInteger)
Compares the current rational number to a BigInteger.
Declaration
public int CompareTo(BigInteger integer)
Parameters
Type | Name | Description |
---|---|---|
BigInteger | integer | The BigInteger to compare with. |
Returns
Type | Description |
---|---|
int | An integer that indicates the relative order of the current rational number and the specified BigInteger. |
Equals(Q?)
Indicates whether the current rational number is equal to another rational number.
Declaration
public bool Equals(Q? other)
Parameters
Type | Name | Description |
---|---|---|
Q | other | The rational number to compare with. |
Returns
Type | Description |
---|---|
bool | true
|
Equals(object?)
Indicates whether the current instance is equal to a specified object.
Declaration
public override bool Equals(object? obj)
Parameters
Type | Name | Description |
---|---|---|
object | obj | The object to compare with the current instance. |
Returns
Type | Description |
---|---|
bool | true
|
Overrides
| Edit this page View SourceForward(int)
Obsolete: This method is obsolete and will be removed.
Declaration
[Obsolete("This method is obsolete and will be removed")]
public Q Forward(int base_)
Parameters
Type | Name | Description |
---|---|---|
int | base_ |
Returns
Type | Description |
---|---|
Q |
GetHashCode()
Returns the hash code for the current instance.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
int | A hash code for the current instance. |
Overrides
| Edit this page View SourceGetPAdicPreperiodic(Q, BaseInt, int)
Declaration
public static BaseInt GetPAdicPreperiodic(Q pAdicPreperiodicQ, BaseInt pAryPreperiodic, int firstExponent)
Parameters
Type | Name | Description |
---|---|---|
Q | pAdicPreperiodicQ | |
BaseInt | pAryPreperiodic | |
int | firstExponent |
Returns
Type | Description |
---|---|
BaseInt |
InBase(int)
Extends the current rational number to a Qb with the specified base.
Declaration
public Qb InBase(int base_)
Parameters
Type | Name | Description |
---|---|---|
int | base_ | The base to convert to. |
Returns
Type | Description |
---|---|
Qb | A new Qb representing the current rational number in the specified base. |
IntegralPartSelective(bool)
This version selects between FIO and FEO mode.
Declaration
protected BigInteger IntegralPartSelective(bool fio)
Parameters
Type | Name | Description |
---|---|---|
bool | fio | If true FIO mode, otherwise FEO mode |
Returns
Type | Description |
---|---|
BigInteger |
Remarks
This property needs to replace the existing version to come in to effect. Current implementation is provided only to give an understanding.
Negation(bool)
Conditionally negates the current rational number.
Declaration
public Q Negation(bool negate)
Parameters
Type | Name | Description |
---|---|---|
bool | negate | A boolean value indicating whether to negate the rational number. |
Returns
Type | Description |
---|---|
Q | A new Q representing the negative value if |
PAdicInterpretation(BaseInt, BaseInt, int)
Declaration
public static Q PAdicInterpretation(BaseInt pAdicPreperiodic, BaseInt pAdicPeriodic, int firstExponent = 0)
Parameters
Type | Name | Description |
---|---|---|
BaseInt | pAdicPreperiodic | |
BaseInt | pAdicPeriodic | |
int | firstExponent |
Returns
Type | Description |
---|---|
Q |
PAdicPeriodic(BaseInt, int)
Declaration
public static Q PAdicPeriodic(BaseInt pAdicPeriodic, int firstPeriodicExponent)
Parameters
Type | Name | Description |
---|---|---|
BaseInt | pAdicPeriodic | |
int | firstPeriodicExponent |
Returns
Type | Description |
---|---|
Q |
PAdicPreperiodic(BaseInt, int)
Declaration
public static Q PAdicPreperiodic(BaseInt pAdicPreperiodic, int firstExponent = 0)
Parameters
Type | Name | Description |
---|---|---|
BaseInt | pAdicPreperiodic | |
int | firstExponent |
Returns
Type | Description |
---|---|
Q |
PAryInterpretation(bool, BaseInt, BaseInt, int)
Returns a Q from the given parts of a base-specific expansion.
Declaration
public static Q PAryInterpretation(bool negative, BaseInt pAryPreperiodic, BaseInt pAryPeriodic, int firstExponent = -1)
Parameters
Type | Name | Description |
---|---|---|
bool | negative | A boolean indicating if the number is negative. |
BaseInt | pAryPreperiodic | The preperiodic part as an integer. |
BaseInt | pAryPeriodic | The periodic part as an integer. |
int | firstExponent | The exponent index of the first coefficient of the number. |
Returns
Type | Description |
---|---|
Q | A new Q representing the rational number derived from the given parts. |
Remarks
This method derives the Numerator and Denominator from the given parameters.
PAryPeriodic(bool, BaseInt, int)
Declaration
public static Q PAryPeriodic(bool negative, BaseInt pAryPeriodic, int firstPeriodicExponent)
Parameters
Type | Name | Description |
---|---|---|
bool | negative | |
BaseInt | pAryPeriodic | |
int | firstPeriodicExponent |
Returns
Type | Description |
---|---|
Q |
PAryPreperiodic(bool, BaseInt, int)
Declaration
public static Q PAryPreperiodic(bool negative, BaseInt pAryPreperiodic, int firstExponent = -1)
Parameters
Type | Name | Description |
---|---|---|
bool | negative | |
BaseInt | pAryPreperiodic | |
int | firstExponent |
Returns
Type | Description |
---|---|
Q |
Pow(Q)
Raises the current rational number to the power of the given exponent.
Declaration
public Q Pow(Q exponent)
Parameters
Type | Name | Description |
---|---|---|
Q | exponent | The exponent to which to raise the current rational number. |
Returns
Type | Description |
---|---|
Q | A new rational number representing the result of the exponentiation. |
Pow(int)
Raises the current rational number to the power of the given integer exponent.
Declaration
public Q Pow(int exponent)
Parameters
Type | Name | Description |
---|---|---|
int | exponent | The integer exponent to which to raise the current rational number. |
Returns
Type | Description |
---|---|
Q | A new rational number representing the result of the exponentiation. |
ShiftedFractions(int)
Light version of ShiftedFractions() that takes a rational number and a base.
Declaration
public IEnumerable<(BigInteger Integer, Q Fraction)> ShiftedFractions(int base_)
Parameters
Type | Name | Description |
---|---|---|
int | base_ | The base to convert to. |
Returns
Type | Description |
---|---|
IEnumerable<(BigInteger Integer, Q Fraction)> | An enumerable sequence of tuples, where each tuple contains the integer part and the fractional part of the rational number in the specified base. |
Remarks
This method does not require the costly creation of a Qb.
See Also
| Edit this page View SourceSquare()
Returns the square of the current rational number.
Declaration
public Q Square()
Returns
Type | Description |
---|---|
Q | A new rational number representing the square of the current rational number. |
ToString()
Returns the default string representation of the rational number
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
string |
Overrides
| Edit this page View SourceToStringCanonical()
Returns the rational number as a simple canonical representation in base 10.
Declaration
public string ToStringCanonical()
Returns
Type | Description |
---|---|
string | A string representing the rational number (in base 10) in the format "numerator/denominator" or just "numerator" if the denominator is 1. |
Remarks
An NaN rational number will yield the string NaN
Examples
Console.WriteLine(new Q(-4,5).ToStringCanonical());
//outputs "-4/5"
|
Edit this page
View Source
ToStringFactorization()
Converts the factorization of the rational number to a string representation.
Declaration
public string ToStringFactorization()
Returns
Type | Description |
---|---|
string | A string representing the factorization of the rational number. |
ToStringFinite(int)
Declaration
public string ToStringFinite(int base_)
Parameters
Type | Name | Description |
---|---|---|
int | base_ |
Returns
Type | Description |
---|---|
string |
TryCastToInt32(out int)
Attempts to cast the rational number to a 32-bit integer, if possible.
Declaration
public bool TryCastToInt32(out int result)
Parameters
Type | Name | Description |
---|---|---|
int | result | The resulting 32-bit integer if the cast is successful. |
Returns
Type | Description |
---|---|
bool | true
|
Operators
| Edit this page View Sourceoperator +(Q, Q)
Sum of two rational numbers.
Declaration
public static Q operator +(Q a, Q b)
Parameters
Type | Name | Description |
---|---|---|
Q | a | The first term. |
Q | b | The second term. |
Returns
Type | Description |
---|---|
Q | A new rational number representing the sum of |
operator +(Q, BigInteger)
Sum of a rational number and an integer.
Declaration
public static Q operator +(Q q, BigInteger integer)
Parameters
Type | Name | Description |
---|---|---|
Q | q | A rational number denoting the first term. |
BigInteger | integer | A BigInteger denoting the second term. |
Returns
Type | Description |
---|---|
Q | A new rational number representing the sum of |
operator +(BigInteger, Q)
Sum of an integer and a rational number.
Declaration
public static Q operator +(BigInteger integer, Q q)
Parameters
Type | Name | Description |
---|---|---|
BigInteger | integer | A BigInteger denoting the first term. |
Q | q | A rational number denoting the second term. |
Returns
Type | Description |
---|---|
Q | A new rational number representing the sum of |
operator --(Q)
Decrements this rational number by one.
Declaration
public static Q operator --(Q a)
Parameters
Type | Name | Description |
---|---|---|
Q | a | The rational number to decrement. |
Returns
Type | Description |
---|---|
Q | A new rational number representing the result of the decrement. |
operator /(Q, Q)
Quotient of two rational numbers.
Declaration
public static Q operator /(Q a, Q b)
Parameters
Type | Name | Description |
---|---|---|
Q | a | The dividend. |
Q | b | The divisor. |
Returns
Type | Description |
---|---|
Q | A new rational number representing the quotient of |
operator /(Q, BigInteger)
Quotient of a rational number and an integer.
Declaration
public static Q operator /(Q q, BigInteger integer)
Parameters
Type | Name | Description |
---|---|---|
Q | q | A rational number denoting the dividend. |
BigInteger | integer | A BigInteger denoting the divisor. |
Returns
Type | Description |
---|---|
Q | A new rational number representing the quotient of |
operator /(BigInteger, Q)
Quotient of am integer and rational number.
Declaration
public static Q operator /(BigInteger integer, Q q)
Parameters
Type | Name | Description |
---|---|---|
BigInteger | integer | A BigInteger denoting the dividend. |
Q | q | A rational number denoting the divisor. |
Returns
Type | Description |
---|---|
Q | A new rational number representing the quotient of |
operator ==(Q, Q)
Indicates whether two rational numbers are equal.
Declaration
public static bool operator ==(Q a, Q b)
Parameters
Type | Name | Description |
---|---|---|
Q | a | The first rational number. |
Q | b | The second rational number. |
Returns
Type | Description |
---|---|
bool | true
|
operator ==(Q, int)
Indicates whether the current rational number is equal to a specified int.
Declaration
public static bool operator ==(Q q, int integer)
Parameters
Type | Name | Description |
---|---|---|
Q | q | The rational number to compare. |
int | integer | The int to compare. |
Returns
Type | Description |
---|---|
bool | true
|
operator ==(Q, BigInteger)
Indicates whether the current rational number is equal to a specified BigInteger.
Declaration
public static bool operator ==(Q q, BigInteger integer)
Parameters
Type | Name | Description |
---|---|---|
Q | q | The rational number to compare. |
BigInteger | integer | The BigInteger to compare. |
Returns
Type | Description |
---|---|
bool | true
|
operator >(Q, Q)
Indicates whether the current rational number is greater than another rational number.
Declaration
public static bool operator >(Q a, Q b)
Parameters
Type | Name | Description |
---|---|---|
Q | a | The first rational number. |
Q | b | The second rational number. |
Returns
Type | Description |
---|---|
bool | true
|
operator >(Q, int)
Indicates whether the current rational number is greater than a specified int.
Declaration
public static bool operator >(Q q, int integer)
Parameters
Type | Name | Description |
---|---|---|
Q | q | The current rational number. |
int | integer | The int to compare. |
Returns
Type | Description |
---|---|
bool | true
|
operator >(Q, BigInteger)
Indicates whether the current rational number is greater than a BigInteger.
Declaration
public static bool operator >(Q q, BigInteger integer)
Parameters
Type | Name | Description |
---|---|---|
Q | q | The current rational number. |
BigInteger | integer | The BigInteger to compare. |
Returns
Type | Description |
---|---|
bool | true
|
operator >=(Q, Q)
Indicates whether the current rational number is greater than or equal to another rational number.
Declaration
public static bool operator >=(Q a, Q b)
Parameters
Type | Name | Description |
---|---|---|
Q | a | The first rational number. |
Q | b | The second rational number. |
Returns
Type | Description |
---|---|
bool | true
|
operator >=(Q, int)
Indicates whether the current rational number is greater than or equal to a specified int.
Declaration
public static bool operator >=(Q q, int integer)
Parameters
Type | Name | Description |
---|---|---|
Q | q | The current rational number. |
int | integer | The int to compare. |
Returns
Type | Description |
---|---|
bool | true
|
operator >=(Q, BigInteger)
Indicates whether the current rational number is greater than or equal to a BigInteger.
Declaration
public static bool operator >=(Q q, BigInteger integer)
Parameters
Type | Name | Description |
---|---|---|
Q | q | The current rational number. |
BigInteger | integer | The BigInteger to compare. |
Returns
Type | Description |
---|---|
bool | true
|
operator ++(Q)
Increments this rational number by one.
Declaration
public static Q operator ++(Q a)
Parameters
Type | Name | Description |
---|---|---|
Q | a | The rational number to increment. |
Returns
Type | Description |
---|---|
Q | A new rational number representing the result of the increment. |
operator !=(Q, Q)
Indicates whether two rational numbers are not equal.
Declaration
public static bool operator !=(Q a, Q b)
Parameters
Type | Name | Description |
---|---|---|
Q | a | The first rational number. |
Q | b | The second rational number. |
Returns
Type | Description |
---|---|
bool | true
|
operator !=(Q, int)
Indicates whether the current rational number is not equal to a specified int.
Declaration
public static bool operator !=(Q q, int integer)
Parameters
Type | Name | Description |
---|---|---|
Q | q | The rational number to compare. |
int | integer | The int to compare. |
Returns
Type | Description |
---|---|
bool | true
|
operator !=(Q, BigInteger)
Indicates whether the current rational number is not equal to a specified BigInteger.
Declaration
public static bool operator !=(Q q, BigInteger integer)
Parameters
Type | Name | Description |
---|---|---|
Q | q | The rational number to compare. |
BigInteger | integer | The BigInteger to compare. |
Returns
Type | Description |
---|---|
bool | true if the current rational number is not equal to the specified |
operator <<(Q, int)
Performs a left bitwise shift on the current rational number.
Declaration
public static Q operator <<(Q a, int shift)
Parameters
Type | Name | Description |
---|---|---|
Q | a | The rational number to shift. |
int | shift | The number of bits to shift. A positive value shifts left, a negative value shifts right. |
Returns
Type | Description |
---|---|
Q | A new rational number representing the result of the shift operation. |
Remarks
If shift
is negative, the shift direction will be reversed,
making this operation equivalent to a right shift. This behavior mirrors the standard
behavior of the C# operators <<
and >>
for integral types, where negative values
reverse the shift direction.
operator <(Q, Q)
Indicates whether the current rational number is less than another rational number.
Declaration
public static bool operator <(Q a, Q b)
Parameters
Type | Name | Description |
---|---|---|
Q | a | The first rational number. |
Q | b | The second rational number. |
Returns
Type | Description |
---|---|
bool | true
|
operator <(Q, int)
Indicates whether the current rational number is less than an int.
Declaration
public static bool operator <(Q q, int integer)
Parameters
Type | Name | Description |
---|---|---|
Q | q | The current rational number. |
int | integer | The int to compare. |
Returns
Type | Description |
---|---|
bool | true
|
operator <(Q, BigInteger)
Indicates whether the current rational number is less than a BigInteger.
Declaration
public static bool operator <(Q q, BigInteger integer)
Parameters
Type | Name | Description |
---|---|---|
Q | q | The current rational number. |
BigInteger | integer | The BigInteger to compare. |
Returns
Type | Description |
---|---|
bool | true
|
operator <=(Q, Q)
Indicates whether the current rational number is less than or equal to another rational number.
Declaration
public static bool operator <=(Q a, Q b)
Parameters
Type | Name | Description |
---|---|---|
Q | a | The first rational number. |
Q | b | The second rational number. |
Returns
Type | Description |
---|---|
bool | true
|
operator <=(Q, int)
Indicates whether the current rational number is less than or equal to an int.
Declaration
public static bool operator <=(Q q, int integer)
Parameters
Type | Name | Description |
---|---|---|
Q | q | The current rational number. |
int | integer | The int to compare. |
Returns
Type | Description |
---|---|
bool | true
|
operator <=(Q, BigInteger)
Indicates whether the current rational number is less than or equal to a BigInteger.
Declaration
public static bool operator <=(Q q, BigInteger integer)
Parameters
Type | Name | Description |
---|---|---|
Q | q | The current rational number. |
BigInteger | integer | The BigInteger to compare. |
Returns
Type | Description |
---|---|
bool | true
|
operator %(Q, Q)
Performs the modulus operation on two rational numbers.
Declaration
public static Q operator %(Q a, Q b)
Parameters
Type | Name | Description |
---|---|---|
Q | a | The left operand. |
Q | b | The right operand. |
Returns
Type | Description |
---|---|
Q | The modulus of |
Remarks
The formula for the modulus operation is:
(a_n / a_d) % (b_n / b_d) = ((a_n * b_d) % (a_d * b_n)) / (a_d * b_d)
where a_n
and a_d
are the numerator and denominator of a
respectively,
and b_n
and b_d
are the numerator and denominator of b
respectively.
operator *(Q, Q)
Product of two rational numbers.
Declaration
public static Q operator *(Q a, Q b)
Parameters
Type | Name | Description |
---|---|---|
Q | a | The first factor. |
Q | b | The second factor. |
Returns
Type | Description |
---|---|
Q | A new rational number representing the product of |
operator *(Q, BigInteger)
Product of a rational number and an integer.
Declaration
public static Q operator *(Q q, BigInteger integer)
Parameters
Type | Name | Description |
---|---|---|
Q | q | A rational number denoting the first factor. |
BigInteger | integer | A BigInteger denoting the second factor. |
Returns
Type | Description |
---|---|
Q | A new rational number representing the product of |
operator *(BigInteger, Q)
Product of an integer and a rational number.
Declaration
public static Q operator *(BigInteger integer, Q q)
Parameters
Type | Name | Description |
---|---|---|
BigInteger | integer | A BigInteger denoting the first factor. |
Q | q | A rational number denoting the second factor. |
Returns
Type | Description |
---|---|
Q | A new rational number representing the product of |
operator >>(Q, int)
Performs a right bitwise shift on the current rational number.
Declaration
public static Q operator >>(Q a, int shift)
Parameters
Type | Name | Description |
---|---|---|
Q | a | The rational number to shift. |
int | shift | The number of bits to shift. A positive value shifts right, a negative value shifts left. |
Returns
Type | Description |
---|---|
Q | A new rational number representing the result of the shift operation. |
Remarks
If shift
is negative, the shift direction will be reversed,
making this operation equivalent to a left shift. This behavior mirrors the standard
behavior of the C# operators <<
and >>
for integral types, where negative values
reverse the shift direction.
operator -(Q, Q)
Difference of two rational numbers.
Declaration
public static Q operator -(Q a, Q b)
Parameters
Type | Name | Description |
---|---|---|
Q | a | The minuend. |
Q | b | The subtrahend. |
Returns
Type | Description |
---|---|
Q | A new rational number representing the difference between |
operator -(Q, BigInteger)
Difference of a rational number and an integer.
Declaration
public static Q operator -(Q q, BigInteger integer)
Parameters
Type | Name | Description |
---|---|---|
Q | q | A rational number denoting the minuend. |
BigInteger | integer | A BigInteger denoting the subtrahend. |
Returns
Type | Description |
---|---|
Q | A new rational number representing the difference of |
operator -(BigInteger, Q)
Difference of an integer and a rational number.
Declaration
public static Q operator -(BigInteger integer, Q q)
Parameters
Type | Name | Description |
---|---|---|
BigInteger | integer | A BigInteger denoting the minuend. |
Q | q | A rational number denoting the subtrahend. |
Returns
Type | Description |
---|---|
Q | A new rational number representing the difference of |
operator -(Q)
Negation of this rational number.
Declaration
public static Q operator -(Q a)
Parameters
Type | Name | Description |
---|---|---|
Q | a | The rational number to negate. |
Returns
Type | Description |
---|---|
Q | A new rational number representing the negated value. |