C# Class Spontaneous.DataModel.Fraction

Inheritance: IComparable, IFormattable
Exibir arquivo Open project: pashkov/Spontaneous Class Usage Examples

Public Properties

Property Type Description
Epsilon Fraction
MaxValue Fraction
MinValue Fraction
NaN Fraction
NegativeInfinity Fraction
PositiveInfinity Fraction
Zero Fraction

Private Properties

Property 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

Public Methods

Method 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

Method 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 method

Compares this Fraction to another Fraction
public CompareTo ( Fraction right ) : int
right Fraction The Fraction to compare against
return int

CompareTo() public method

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)
return int

CrossReducePair() public static method

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]
return void

Equals() public method

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

Fraction() public method

Default constructor; default value is NaN.
public Fraction ( ) : System
return System

Fraction() public method

Construct a Fraction from another fraction
public Fraction ( Fraction f ) : System
f Fraction
return System

Fraction() public method

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

Fraction() public method

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

Fraction() public method

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)
return System

Fraction() public method

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
return System

GetHashCode() public method

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

Inverse() public method

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

Inverted() public static method

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
return Fraction

Inverted() public static method

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
return Fraction

IsInfinity() public method

Determines if a Fraction represents Any Infinity
public IsInfinity ( ) : bool
return bool

IsNaN() public method

Determines if a Fraction represents a Not-a-Number
public IsNaN ( ) : bool
return bool

IsNegativeInfinity() public method

Determines if a Fraction represents Negative Infinity
public IsNegativeInfinity ( ) : bool
return bool

IsPositiveInfinity() public method

Determines if a Fraction represents Positive Infinity
public IsPositiveInfinity ( ) : bool
return bool

ReduceFraction() public static method

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]
return void

ToDouble() public method

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

ToFraction() public static method

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
return Fraction

ToFraction() public static method

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

ToFraction() public static method

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
return Fraction

ToInt32() public method

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
return System.Int32

ToInt64() public method

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
return System.Int64

ToString() public method

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
return string

operator() public static method

public static operator ( ) : Fraction
return Fraction

operator() public static method

public static operator ( ) : bool
return bool

Property Details

Epsilon public_oe static_oe property

public static Fraction,Spontaneous.DataModel Epsilon
return Fraction

MaxValue public_oe static_oe property

public static Fraction,Spontaneous.DataModel MaxValue
return Fraction

MinValue public_oe static_oe property

public static Fraction,Spontaneous.DataModel MinValue
return Fraction

NaN public_oe static_oe property

public static Fraction,Spontaneous.DataModel NaN
return Fraction

NegativeInfinity public_oe static_oe property

public static Fraction,Spontaneous.DataModel NegativeInfinity
return Fraction

PositiveInfinity public_oe static_oe property

public static Fraction,Spontaneous.DataModel PositiveInfinity
return Fraction

Zero public_oe static_oe property

public static Fraction,Spontaneous.DataModel Zero
return Fraction