C# Класс 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
Показать файл Открыть проект Примеры использования класса

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

Метод Описание
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

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

Метод Описание
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

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

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

The function replicates current Fraction object
public Duplicate ( ) : Fraction
Результат Fraction

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

checks whether two fractions are equal
public Equals ( object obj ) : bool
obj object
Результат bool

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

Constructors
public Fraction ( ) : System
Результат System

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

public Fraction ( double dDecimalValue ) : System
dDecimalValue double
Результат System

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

public Fraction ( long iWholeNumber ) : System
iWholeNumber long
Результат System

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

public Fraction ( long iNumerator, long iDenominator ) : System
iNumerator long
iDenominator long
Результат System

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

public Fraction ( string strValue ) : System
strValue string
Результат System

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

returns a hash code for this fraction
public GetHashCode ( ) : int
Результат int

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

The function returns the inverse of a Fraction object
public static Inverse ( Fraction frac1 ) : Fraction
frac1 Fraction
Результат Fraction

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

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
Результат void

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

The function returns the current Fraction object as double
public ToDouble ( ) : double
Результат double

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

The function takes a Fraction object and returns its value as double
public static ToDouble ( Fraction frac ) : double
frac Fraction
Результат double

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

The function takes a floating point number as an argument and returns its corresponding reduced fraction
public static ToFraction ( double dValue ) : Fraction
dValue double
Результат Fraction

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

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
Результат Fraction

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

The function returns the current Fraction object as a string
public ToString ( ) : string
Результат string

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

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

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

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