C# Class Spontaneous.DataModel.Fraction

Inheritance: IComparable, IFormattable
Afficher le fichier Open project: pashkov/Spontaneous Class Usage Examples

Méthodes publiques

Свойство Type Description
Epsilon Fraction
MaxValue Fraction
MinValue Fraction
NaN Fraction
NegativeInfinity Fraction
PositiveInfinity Fraction
Zero Fraction

Private Properties

Свойство Type Description
Add Fraction
CompareEquality bool
ConvertPositiveDouble Fraction
Fraction System
GCD long
IndeterminantCompare int
IndeterminateTypeName string
Modulus Fraction
Multiply Fraction
Negate Fraction
NormalizeIndeterminate Indeterminates
System string

Méthodes publiques

Méthode Description
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

Private Methods

Méthode Description
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

Method Details

CompareTo() public méthode

Compares this Fraction to another Fraction
public CompareTo ( Fraction right ) : int
right Fraction The Fraction to compare against
Résultat int

CompareTo() public méthode

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)
Résultat int

CrossReducePair() public static méthode

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]
Résultat void

Equals() public méthode

Compares for equality the current Fraction to the value passed.
public Equals ( object obj ) : bool
obj object A Fraction,
Résultat bool

Fraction() public méthode

Default constructor; default value is NaN.
public Fraction ( ) : System
Résultat System

Fraction() public méthode

Construct a Fraction from another fraction
public Fraction ( Fraction f ) : System
f Fraction
Résultat System

Fraction() public méthode

Construct a Fraction from a floating-point value
public Fraction ( double floatingPointNumber ) : System
floatingPointNumber double The value
Résultat System

Fraction() public méthode

Construct a Fraction from an integral value
The denominator will be 1
public Fraction ( long wholeNumber ) : System
wholeNumber long The value (eventual numerator)
Résultat System

Fraction() public méthode

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)
Résultat System

Fraction() public méthode

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
Résultat System

GetHashCode() public méthode

Returns a hash code generated from the current Fraction
Reduces (in-place) the Fraction first.
public GetHashCode ( ) : int
Résultat int

Inverse() public méthode

Inverts a Fraction
Does NOT throw for zero Numerators as later use of the fraction will catch the error.
public Inverse ( ) : Fraction
Résultat Fraction

Inverted() public static méthode

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
Résultat Fraction

Inverted() public static méthode

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
Résultat Fraction

IsInfinity() public méthode

Determines if a Fraction represents Any Infinity
public IsInfinity ( ) : bool
Résultat bool

IsNaN() public méthode

Determines if a Fraction represents a Not-a-Number
public IsNaN ( ) : bool
Résultat bool

IsNegativeInfinity() public méthode

Determines if a Fraction represents Negative Infinity
public IsNegativeInfinity ( ) : bool
Résultat bool

IsPositiveInfinity() public méthode

Determines if a Fraction represents Positive Infinity
public IsPositiveInfinity ( ) : bool
Résultat bool

ReduceFraction() public static méthode

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]
Résultat void

ToDouble() public méthode

Get the value of the Fraction object as double with full support for NaNs and infinities
public ToDouble ( ) : double
Résultat double

ToFraction() public static méthode

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
Résultat Fraction

ToFraction() public static méthode

Converts a long value to the exact Fraction
public static ToFraction ( long inValue ) : Fraction
inValue long The long to convert
Résultat Fraction

ToFraction() public static méthode

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
Résultat Fraction

ToInt32() public méthode

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
Résultat System.Int32

ToInt64() public méthode

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
Résultat System.Int64

ToString() public méthode

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
Résultat string

operator() public static méthode

public static operator ( ) : Fraction
Résultat Fraction

operator() public static méthode

public static operator ( ) : bool
Résultat bool

Property Details

Epsilon public_oe static_oe property

public static Fraction,Spontaneous.DataModel Epsilon
Résultat Fraction

MaxValue public_oe static_oe property

public static Fraction,Spontaneous.DataModel MaxValue
Résultat Fraction

MinValue public_oe static_oe property

public static Fraction,Spontaneous.DataModel MinValue
Résultat Fraction

NaN public_oe static_oe property

public static Fraction,Spontaneous.DataModel NaN
Résultat Fraction

NegativeInfinity public_oe static_oe property

public static Fraction,Spontaneous.DataModel NegativeInfinity
Résultat Fraction

PositiveInfinity public_oe static_oe property

public static Fraction,Spontaneous.DataModel PositiveInfinity
Résultat Fraction

Zero public_oe static_oe property

public static Fraction,Spontaneous.DataModel Zero
Résultat Fraction