C# Class EncryptionAlgorithms.Fraction

Class name: Fraction Developed by: Syed Mehroz Alam Email: [email protected] URL: Programming Home "http://www.geocities.com/smehrozalam/" Version: 2.0 What's new in version 2.0: * Changed Numerator and Denominator from Int32(integer) to Int64(long) for increased range * renamed ConvertToString() to (overloaded) ToString() * added the capability of detecting/raising overflow exceptions * Fixed the bug that very small numbers e.g. 0.00000001 could not be converted to fraction * Other minor bugs fixed Properties: Numerator: Set/Get value for Numerator Denominator: Set/Get value for Numerator Value: Set an integer value for the fraction Constructors: no arguments: initializes fraction as 0/1 (Numerator, Denominator): initializes fraction with the given numerator and denominator values (integer): initializes fraction with the given integer value (long): initializes fraction with the given long value (double): initializes fraction with the given double value (string): initializes fraction with the given string value the string can be an in the form of and integer, double or fraction. e.g it can be like "123" or "123.321" or "123/456" Public Methods (Description is given with respective methods' definitions) (override) string ToString(Fraction) Fraction ToFraction(string) Fraction ToFraction(double) double ToDouble(Fraction) Fraction Duplicate() Fraction Inverse(integer) Fraction Inverse(Fraction) ReduceFraction(Fraction) Equals(object) GetHashCode() Private Methods (Description is given with respective methods' definitions) Initialize(Numerator, Denominator) Fraction Negate(Fraction) Fraction Add(Fraction1, Fraction2) Overloaded Operators (overloaded for Fractions, Integers and Doubles) Unary: - Binary: +,-,*,/ Relational and Logical Operators: ==,!=,<,>,<=,>= Overloaded user-defined conversions Implicit: From double/long/string to Fraction Explicit: From Fraction to double/string
显示文件 Open project: Omar-Salem/Classical-Encryption-Techniques Class Usage Examples

Public Methods

Method Description
Duplicate ( ) : Fraction

The function replicates current Fraction object

Equals ( object obj ) : bool

checks whether two fractions are equal

Fraction ( ) : System

Constructors

Fraction ( double dDecimalValue ) : System
Fraction ( long iWholeNumber ) : System
Fraction ( long iNumerator, long iDenominator ) : System
Fraction ( string strValue ) : System
GetHashCode ( ) : int

returns a hash code for this fraction

Inverse ( Fraction frac1 ) : Fraction

The function returns the inverse of a Fraction object

ReduceFraction ( Fraction frac ) : void

The function reduces(simplifies) a Fraction object by dividing both its numerator and denominator by their GCD

ToDouble ( ) : double

The function returns the current Fraction object as double

ToDouble ( Fraction frac ) : double

The function takes a Fraction object and returns its value as double

ToFraction ( double dValue ) : Fraction

The function takes a floating point number as an argument and returns its corresponding reduced fraction

ToFraction ( string strValue ) : Fraction

The function takes an string as an argument and returns its corresponding reduced fraction the string can be an in the form of and integer, double or fraction. e.g it can be like "123" or "123.321" or "123/456"

ToString ( ) : string

The function returns the current Fraction object as a string

operator ( ) : Fraction
operator ( ) : bool

Private Methods

Method Description
Add ( Fraction frac1, Fraction frac2 ) : Fraction

internal functions for binary operations

GCD ( long iNo1, long iNo2 ) : long

The function returns GCD of two numbers (used for reducing a Fraction)

Initialize ( long iNumerator, long iDenominator ) : void

Internal function for constructors

Multiply ( Fraction frac1, Fraction frac2 ) : Fraction
Negate ( Fraction frac1 ) : Fraction

internal function for negation

Method Details

Duplicate() public method

The function replicates current Fraction object
public Duplicate ( ) : Fraction
return Fraction

Equals() public method

checks whether two fractions are equal
public Equals ( object obj ) : bool
obj object
return bool

Fraction() public method

Constructors
public Fraction ( ) : System
return System

Fraction() public method

public Fraction ( double dDecimalValue ) : System
dDecimalValue double
return System

Fraction() public method

public Fraction ( long iWholeNumber ) : System
iWholeNumber long
return System

Fraction() public method

public Fraction ( long iNumerator, long iDenominator ) : System
iNumerator long
iDenominator long
return System

Fraction() public method

public Fraction ( string strValue ) : System
strValue string
return System

GetHashCode() public method

returns a hash code for this fraction
public GetHashCode ( ) : int
return int

Inverse() public static method

The function returns the inverse of a Fraction object
public static Inverse ( Fraction frac1 ) : Fraction
frac1 Fraction
return Fraction

ReduceFraction() public static method

The function reduces(simplifies) a Fraction object by dividing both its numerator and denominator by their GCD
public static ReduceFraction ( Fraction frac ) : void
frac Fraction
return void

ToDouble() public method

The function returns the current Fraction object as double
public ToDouble ( ) : double
return double

ToDouble() public static method

The function takes a Fraction object and returns its value as double
public static ToDouble ( Fraction frac ) : double
frac Fraction
return double

ToFraction() public static method

The function takes a floating point number as an argument and returns its corresponding reduced fraction
public static ToFraction ( double dValue ) : Fraction
dValue double
return Fraction

ToFraction() public static method

The function takes an string as an argument and returns its corresponding reduced fraction the string can be an in the form of and integer, double or fraction. e.g it can be like "123" or "123.321" or "123/456"
public static ToFraction ( string strValue ) : Fraction
strValue string
return Fraction

ToString() public method

The function returns the current Fraction object as a string
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