Struct Rational
Represents a rational number.
public struct Rational : IEquatable<Rational>
- Implements
- Extension Methods
Remarks
The Rational structure operates under the following rules:
- 0/0 is legal and will be interpreted as 0/1.
- 0/anything is interpreted as zero.
- If you are representing a whole number, the denominator should be 1.
Constructors
Rational(int, int)
Represents a rational number.
public Rational(int numerator, int denominator)
Parameters
numeratorintThe numerator (top) of the rational number.
denominatorintThe denominator (bottom) of the rational number.
Remarks
The Rational structure operates under the following rules:
- 0/0 is legal and will be interpreted as 0/1.
- 0/anything is interpreted as zero.
- If you are representing a whole number, the denominator should be 1.
Fields
Denominator
An value representing the bottom of the rational number.
public int Denominator
Field Value
Numerator
An value representing the top of the rational number.
public int Numerator
Field Value
Methods
Equals(Rational)
Indicates whether the current object is equal to another object of the same type.
public readonly bool Equals(Rational other)
Parameters
otherRationalAn object to compare with this object.
Returns
Equals(object)
Indicates whether this instance and a specified object are equal.
public override readonly 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.
GetHashCode()
Returns the hash code for this instance.
public override readonly int GetHashCode()
Returns
- int
A 32-bit signed integer that is the hash code for this instance.
ToString()
Returns the string representation of this Rational, including its approximate real value.
public override string ToString()
Returns
Operators
operator ==(Rational, Rational)
public static bool operator ==(Rational left, Rational right)
Parameters
Returns
implicit operator Rational(int)
Returns a new Rational from an integer value.
public static implicit operator Rational(int value)
Parameters
valueintThe integer value.
Returns
- Rational
The integer
valueas a rational number with denominator 1.
operator !=(Rational, Rational)
public static bool operator !=(Rational left, Rational right)