- Inherits from:
- Object
- Conforms to:
- DComparable, DSimpleArithmetic, DTextable
- Declared in:
- DFraction.h
Object
|
+---DFraction
Class Description
The fraction class implements a number of methods for working with fractions.
- Last modified:
- 13-Jun-2005 (DFraction.h)
Instance Variables
- private int _num
- the numerator
- private int _denom
- the denominator
- Constructors
- - (DFraction *) init
- Initialise a zero fraction
- Returns:
- the object
- - (DFraction *) init :(int) num :(int) denom
- Initialise a fraction
- Parameters:
- num - the numerator
denom - the denominator
- Returns:
- the object
- Member methods
- - (int) denominator
- Get the denominator
- Returns:
- the denominator
- - (DFraction *) denominator :(int) denom
- Set the denominator of the fraction
- Parameters:
- denom - the denominator
- Returns:
- the object
- - (DFraction *) move :(DFraction *) other
- Move an other object in this object
- Parameters:
- other - the other object
- Returns:
- this object
- - (int) numerator
- Get the numerator
- Returns:
- the numerator
- - (DFraction *) numerator :(int) num
- Set the numerator
- Parameters:
- num - the numerator of the fraction
- Returns:
- the object
- - (DFraction *) set :(int) num :(int) denom
- Set the numerator and denominator of the fraction
- Parameters:
- num - the numerator
denom - the denominator
- Returns:
- the object
- Methods on fractions
- - (DFraction *) add :(DFraction *) other
- Add with an other fraction
- Parameters:
- other - the fraction
- Returns:
- the object
- - (DFraction *) add :(DFraction *) fr1 :(DFraction *) fr2
- Add two fractions and store the result in the object
- Parameters:
- fr1 - the first fraction
fr2 - the second fraction
- Returns:
- the object
- - (DFraction *) div :(DFraction *) other
- Divide with an other fraction
- Parameters:
- other - the divider
- Returns:
- the object
- - (DFraction *) div :(DFraction *) fraction :(DFraction *) divider
- Divide two fractions and store the result in the object
- Parameters:
- fraction - the fraction
divider - the divider
- Returns:
- the object
- - (DFraction *) invert
- Invert the fraction
- Returns:
- the object
- - (DFraction *) mul :(DFraction *) other
- Multiply with an other fraction
- Parameters:
- other - the other fraction
- Returns:
- the object
- - (DFraction *) mul :(DFraction *) fr1 :(DFraction *) fr2
- Multiply two fractions and store the result in the object
- Parameters:
- fr1 - the first fraction
fr2 - the second fraction
- Returns:
- the object
- - (DFraction *) norm
- Normalize the fraction
- Returns:
- the object
- - (DFraction *) sub :(DFraction *) other
- Subract with an other fraction
- Parameters:
- other - the fraction
- Returns:
- the object
- - (DFraction *) sub :(DFraction *) fr1 :(DFraction *) fr2
- Subtract two fractions and store the result in the object
- Parameters:
- fr1 - the first fraction
fr2 - the second fraction
- Returns:
- the object
- - (double) toDouble
- Convert to a double
- Returns:
- the double
- Class methods
- + (int) gcd :(int) a :(int) b
- Calculate the Greatest Common Divider
- Parameters:
- a - the first number
b - the second number
- Returns:
- the greatest common divider
- + (int) lcm :(int) a :(int) b
- Calculate the Least Common Multiplier
- Parameters:
- a - the first number
b - the second number
- Returns:
- the least common multiplier
- Textable protocol methods
- - (DText *) toText
- Convert to a text string
- Returns:
- a (new) text string with the complex number
- Comparable protocol method
- - (int) compare :(DFraction *) other
- Compare with another fraction (using doubles)
- Parameters:
- other - the other fraction
- Returns:
- the compare result (-1,0,1)
generated 08-Jan-2006 by ObjcDoc 3.0.0