C# Класс Spontaneous.DataModel.Fraction

Наследование: IComparable, IFormattable
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
Epsilon Fraction
MaxValue Fraction
MinValue Fraction
NaN Fraction
NegativeInfinity Fraction
PositiveInfinity Fraction
Zero Fraction

Private Properties

Свойство Тип Описание
Add Fraction
CompareEquality bool
ConvertPositiveDouble Fraction
Fraction System
GCD long
IndeterminantCompare int
IndeterminateTypeName string
Modulus Fraction
Multiply Fraction
Negate Fraction
NormalizeIndeterminate Indeterminates
System string

Открытые методы

Метод Описание
CompareTo ( Fraction right ) : int

Compares this Fraction to another Fraction

CompareTo ( object obj ) : int

Compares an object to this Fraction

Will convert an object from longs, doubles, and strings as this is a value-type.

CrossReducePair ( Fraction frac1, Fraction frac2 ) : void

Cross-reduces a pair of Fractions so that we have the best GCD-reduced values for multiplication

Modifies the input arguments in-place!

Equals ( object obj ) : bool

Compares for equality the current Fraction to the value passed.

Fraction ( ) : System

Default constructor; default value is NaN.

Fraction ( Fraction f ) : System

Construct a Fraction from another fraction

Fraction ( double floatingPointNumber ) : System

Construct a Fraction from a floating-point value

Fraction ( long wholeNumber ) : System

Construct a Fraction from an integral value

The denominator will be 1

Fraction ( long numerator, long denominator ) : System

Construct a Fraction from a numerator, denominator pair

Will reduce the fraction to smallest possible denominator

Fraction ( string inValue ) : System

Construct a Fraction from a string in any legal format

Will reduce the fraction to smallest possible denominator

GetHashCode ( ) : int

Returns a hash code generated from the current Fraction

Reduces (in-place) the Fraction first.

Inverse ( ) : Fraction

Inverts a Fraction

Does NOT throw for zero Numerators as later use of the fraction will catch the error.

Inverted ( double value ) : Fraction

Creates an inverted Fraction

Does NOT throw for zero Numerators as later use of the fraction will catch the error.

Inverted ( long value ) : Fraction

Creates an inverted Fraction

Does NOT throw for zero Numerators as later use of the fraction will catch the error.

IsInfinity ( ) : bool

Determines if a Fraction represents Any Infinity

IsNaN ( ) : bool

Determines if a Fraction represents a Not-a-Number

IsNegativeInfinity ( ) : bool

Determines if a Fraction represents Negative Infinity

IsPositiveInfinity ( ) : bool

Determines if a Fraction represents Positive Infinity

ReduceFraction ( Fraction frac ) : void

Reduces (simplifies) a Fraction by dividing down to lowest possible denominator (via GCD)

Modifies the input arguments in-place! Will normalize the NaN and infinites representation. Will set Denominator to 1 for any zero numerator. Moves sign to the Numerator.

ToDouble ( ) : double

Get the value of the Fraction object as double with full support for NaNs and infinities

ToFraction ( double inValue ) : Fraction

Converts a double value to the approximate Fraction

Supports double.NaN, double.PositiveInfinity and double.NegativeInfinity

ToFraction ( long inValue ) : Fraction

Converts a long value to the exact Fraction

ToFraction ( string inValue ) : Fraction

Converts a string to the corresponding reduced fraction

Four forms are supported, as a plain integer, as a double, or as Numerator/Denominator and the representations for NaN and the infinites

ToInt32 ( ) : Int32

Get the integral value of the Fraction object as int/Int32

If the value is not a true integer, the fractional part is discarded (truncated toward zero). If the valid exceeds the range of an Int32 and exception is thrown.

ToInt64 ( ) : System.Int64

Get the integral value of the Fraction object as long/Int64

If the value is not a true integer, the fractional part is discarded (truncated toward zero). If the valid exceeds the range of an Int32, no special handling is guaranteed.

ToString ( ) : string

Get the value of the Fraction as a string, with proper representation for NaNs and infinites

The current culture determines the textual representation the Indeterminates

operator ( ) : Fraction
operator ( ) : bool

Приватные методы

Метод Описание
Add ( Fraction left, Fraction right ) : Fraction

Adds two Fractions

CompareEquality ( Fraction right, bool notEqualCheck ) : bool

Compares for equality the current Fraction to the value passed.

ConvertPositiveDouble ( int sign, double inValue ) : Fraction
Fraction ( Indeterminates type ) : System

Private constructor to synthesize a Fraction for indeterminates (NaN and infinites)

GCD ( long left, long right ) : long

Computes the greatest common divisor for two values

IndeterminantCompare ( Indeterminates leftType, Fraction right ) : int

Determines how this Fraction, of an indeterminate type, compares to another Fraction

NaN is less than anything except NaN and Negative Infinity. Negative Infinity is less than anything except Negative Infinity. Positive Infinity is greater than anything except Positive Infinity.

IndeterminateTypeName ( long numerator ) : string

Gives the culture-related representation of the indeterminate types NaN, PositiveInfinity and NegativeInfinity

Only the sign and zero/non-zero information is relevant.

Modulus ( Fraction left, Fraction right ) : Fraction

Returns the modulus (remainder after dividing) two Fractions

Multiply ( Fraction left, Fraction right ) : Fraction

Multiplies two Fractions

Negate ( Fraction frac ) : Fraction

Negates the Fraction

NormalizeIndeterminate ( long numerator ) : Indeterminates

Gives the normalize representation of the indeterminate types NaN, PositiveInfinity and NegativeInfinity

Only the sign and zero/non-zero information is relevant.

System ( string format, IFormatProvider formatProvider ) : string

Описание методов

CompareTo() публичный Метод

Compares this Fraction to another Fraction
public CompareTo ( Fraction right ) : int
right Fraction The Fraction to compare against
Результат int

CompareTo() публичный Метод

Compares an object to this Fraction
Will convert an object from longs, doubles, and strings as this is a value-type.
public CompareTo ( object obj ) : int
obj object The object to compare against (null is less than everything)
Результат int

CrossReducePair() публичный статический Метод

Cross-reduces a pair of Fractions so that we have the best GCD-reduced values for multiplication
Modifies the input arguments in-place!
public static CrossReducePair ( Fraction frac1, Fraction frac2 ) : void
frac1 Fraction The first Fraction [WILL BE MODIFIED IN PLACE]
frac2 Fraction The second Fraction [WILL BE MODIFIED IN PLACE]
Результат void

Equals() публичный Метод

Compares for equality the current Fraction to the value passed.
public Equals ( object obj ) : bool
obj object A Fraction,
Результат bool

Fraction() публичный Метод

Default constructor; default value is NaN.
public Fraction ( ) : System
Результат System

Fraction() публичный Метод

Construct a Fraction from another fraction
public Fraction ( Fraction f ) : System
f Fraction
Результат System

Fraction() публичный Метод

Construct a Fraction from a floating-point value
public Fraction ( double floatingPointNumber ) : System
floatingPointNumber double The value
Результат System

Fraction() публичный Метод

Construct a Fraction from an integral value
The denominator will be 1
public Fraction ( long wholeNumber ) : System
wholeNumber long The value (eventual numerator)
Результат System

Fraction() публичный Метод

Construct a Fraction from a numerator, denominator pair
Will reduce the fraction to smallest possible denominator
public Fraction ( long numerator, long denominator ) : System
numerator long The numerator (top number)
denominator long The denominator (bottom number)
Результат System

Fraction() публичный Метод

Construct a Fraction from a string in any legal format
Will reduce the fraction to smallest possible denominator
public Fraction ( string inValue ) : System
inValue string A string with a legal fraction input format
Результат System

GetHashCode() публичный Метод

Returns a hash code generated from the current Fraction
Reduces (in-place) the Fraction first.
public GetHashCode ( ) : int
Результат int

Inverse() публичный Метод

Inverts a Fraction
Does NOT throw for zero Numerators as later use of the fraction will catch the error.
public Inverse ( ) : Fraction
Результат Fraction

Inverted() публичный статический Метод

Creates an inverted Fraction
Does NOT throw for zero Numerators as later use of the fraction will catch the error.
public static Inverted ( double value ) : Fraction
value double
Результат Fraction

Inverted() публичный статический Метод

Creates an inverted Fraction
Does NOT throw for zero Numerators as later use of the fraction will catch the error.
public static Inverted ( long value ) : Fraction
value long
Результат Fraction

IsInfinity() публичный Метод

Determines if a Fraction represents Any Infinity
public IsInfinity ( ) : bool
Результат bool

IsNaN() публичный Метод

Determines if a Fraction represents a Not-a-Number
public IsNaN ( ) : bool
Результат bool

IsNegativeInfinity() публичный Метод

Determines if a Fraction represents Negative Infinity
public IsNegativeInfinity ( ) : bool
Результат bool

IsPositiveInfinity() публичный Метод

Determines if a Fraction represents Positive Infinity
public IsPositiveInfinity ( ) : bool
Результат bool

ReduceFraction() публичный статический Метод

Reduces (simplifies) a Fraction by dividing down to lowest possible denominator (via GCD)
Modifies the input arguments in-place! Will normalize the NaN and infinites representation. Will set Denominator to 1 for any zero numerator. Moves sign to the Numerator.
public static ReduceFraction ( Fraction frac ) : void
frac Fraction The Fraction to be reduced [WILL BE MODIFIED IN PLACE]
Результат void

ToDouble() публичный Метод

Get the value of the Fraction object as double with full support for NaNs and infinities
public ToDouble ( ) : double
Результат double

ToFraction() публичный статический Метод

Converts a double value to the approximate Fraction
Supports double.NaN, double.PositiveInfinity and double.NegativeInfinity
public static ToFraction ( double inValue ) : Fraction
inValue double The double to convert
Результат Fraction

ToFraction() публичный статический Метод

Converts a long value to the exact Fraction
public static ToFraction ( long inValue ) : Fraction
inValue long The long to convert
Результат Fraction

ToFraction() публичный статический Метод

Converts a string to the corresponding reduced fraction
Four forms are supported, as a plain integer, as a double, or as Numerator/Denominator and the representations for NaN and the infinites
public static ToFraction ( string inValue ) : Fraction
inValue string The string representation of a fractional value
Результат Fraction

ToInt32() публичный Метод

Get the integral value of the Fraction object as int/Int32
If the value is not a true integer, the fractional part is discarded (truncated toward zero). If the valid exceeds the range of an Int32 and exception is thrown.
Will throw a FractionException for NaN, PositiveInfinity /// or NegativeInfinity with the InnerException set to a System.NotFiniteNumberException.
public ToInt32 ( ) : Int32
Результат System.Int32

ToInt64() публичный Метод

Get the integral value of the Fraction object as long/Int64
If the value is not a true integer, the fractional part is discarded (truncated toward zero). If the valid exceeds the range of an Int32, no special handling is guaranteed.
Will throw a FractionException for NaN, PositiveInfinity /// or NegativeInfinity with the InnerException set to a System.NotFiniteNumberException.
public ToInt64 ( ) : System.Int64
Результат System.Int64

ToString() публичный Метод

Get the value of the Fraction as a string, with proper representation for NaNs and infinites
The current culture determines the textual representation the Indeterminates
public ToString ( ) : string
Результат string

operator() публичный статический Метод

public static operator ( ) : Fraction
Результат Fraction

operator() публичный статический Метод

public static operator ( ) : bool
Результат bool

Описание свойств

Epsilon публичное статическое свойство

public static Fraction,Spontaneous.DataModel Epsilon
Результат Fraction

MaxValue публичное статическое свойство

public static Fraction,Spontaneous.DataModel MaxValue
Результат Fraction

MinValue публичное статическое свойство

public static Fraction,Spontaneous.DataModel MinValue
Результат Fraction

NaN публичное статическое свойство

public static Fraction,Spontaneous.DataModel NaN
Результат Fraction

NegativeInfinity публичное статическое свойство

public static Fraction,Spontaneous.DataModel NegativeInfinity
Результат Fraction

PositiveInfinity публичное статическое свойство

public static Fraction,Spontaneous.DataModel PositiveInfinity
Результат Fraction

Zero публичное статическое свойство

public static Fraction,Spontaneous.DataModel Zero
Результат Fraction