- Inherits from:
- Object
- Conforms to:
- DComparable, DParsable, DSimpleArithmetic, DTextable
- Declared in:
- DBigFraction.h
Object
|
+---DBigFraction
Class Description
The big fraction class implements a number of methods for working with
arbitrary large fraction numbers, also called rational numbers.
The class uses the excellent gmp library for the actual calculations.
- Last modified:
- 31-Oct-2007 (DBigFraction.h)
Instance Variables
- private void *_value
- the big fraction value
- Constructors
- - (DBigFraction *) init
- Initialise to fraction zero
- Returns:
- the object
- - (DBigFraction *) init :(double) value
- Initialise the fraction with a double
- Parameters:
- value - the double value
- Returns:
- the object
- - (DBigFraction *) init :(const char *) cstring :(int) base
- Initialise the fraction with a text string
- Parameters:
- cstring - the cstring with the fraction
base - the base for the fraction
- Returns:
- the object
- Copy constructor
- - shallowCopy
- Do a shallow copy of the big fraction
- Returns:
- the object
- Deconstructor
- - free
- Free a big fraction
- Returns:
- the object
- Set methods
- - (DBigFraction *) clear
- Set the big fraction to zero
- Returns:
- the object
- - (DBigFraction *) fraction :(int) num :(int) denom
- Set the big fraction with (small) numerator and denominator
- Parameters:
- num - the numerator
denom - the denominator
- Returns:
- the object
- - (DBigFraction *) move :(DBigFraction *) other
- Move an other object in this object
- Parameters:
- other - the other object
- Returns:
- this object
- - (DBigFraction *) set :(double) value
- Set the big fraction with a double
- Parameters:
- value - the double value
- Returns:
- the object
- - (BOOL) set :(const char *) cstring :(int) base
- Set the big fraction with a text string
- Parameters:
- cstring - the cstring with the fraction
base - the base of the number (2..36)
- Returns:
- success
- Get methods
- - (long) denominator
- Get the denominator (as small integer)
- Returns:
- the denominator
- - (double) get
- Get the big fraction as a double
- Returns:
- the double
- - (DText *) get :(int) base
- Get the big fraction as a text string
- Parameters:
- base - the base for the text string (2..36)
- Returns:
- a (new) text string (or nil)
- - (long) numerator
- Get the numerator (as small integer)
- Returns:
- the numerator
- - (double) toDouble
- Convert to a double
- Returns:
- the double
- Methods on big fraction numbers
- - (DBigFraction *) abs
- Absolute the big fraction
- Returns:
- the object
- - (DBigFraction *) add :(DBigFraction *) other
- Add with an other big fraction
- Parameters:
- other - the big fraction
- Returns:
- the object
- - (DBigFraction *) add :(DBigFraction *) src1 :(DBigFraction *) src2
- Add two big fractions and store the result in the object
- Parameters:
- src1 - the first big fraction
src2 - the second big fraction
- Returns:
- the object
- - (DBigFraction *) div :(DBigFraction *) other
- Divide with an other big fraction
- Parameters:
- other - the divisor big fraction
- Returns:
- the object
- - (DBigFraction *) div :(DBigFraction *) src1 :(DBigFraction *) src2
- Divide two big fractions and store the result in the object
- Parameters:
- src1 - the dividend big fraction
src2 - the divisor big fraction
- Returns:
- the object
- - (DBigFraction *) invert
- Invert the big fraction
- Returns:
- the object
- - (DBigFraction *) mul :(DBigFraction *) other
- Multiply with an other big fraction
- Parameters:
- other - the big fraction
- Returns:
- the object
- - (DBigFraction *) mul :(DBigFraction *) src1 :(DBigFraction *) src2
- Multiply two big fractions and store the result in the object
- Parameters:
- src1 - the first big fraction
src2 - the second big fraction
- Returns:
- the object
- - (DBigFraction *) negate
- Negate the big fraction
- Returns:
- the object
- - (DBigFraction *) norm
- Normalize the big fraction
- Returns:
- the object
- - (DBigFraction *) sub :(DBigFraction *) other
- Subract with an other big fraction
- Parameters:
- other - the big fraction
- Returns:
- the object
- - (DBigFraction *) sub :(DBigFraction *) src1 :(DBigFraction *) src2
- Subract two big fractions and store the result in the object
- Parameters:
- src1 - the first big fraction
src2 - the second big fraction
- Returns:
- the object
- DComparable protocol implementation
- - (int) compare :(DBigFraction *) other
- Compare with an other big fraction
- Parameters:
- other - the other big fraction
- Returns:
- the compare result ( <0, 0, 0> )
- Textable protocol implementation
- - (DText *) toText
- Convert to a decimal text string
- Returns:
- a (new) text string with the big fraction (or nil)
- DParsable protocol implementation
- - (int) fromString :(char **) cstr
- Parse a string for a big fraction. Format: [space]*[+-]number/number
and number is one of:
decimal: [1..9][0..9]*
hexadecimal: 0x[0..9a..f]*
octal: 0[0..7]*
- Parameters:
- cstr - the string to be parsed (moved to the first non-parsable char)
- Returns:
- the result (0,ERANGE,ENODATA)
generated 05-Nov-2007 by ObjcDoc 3.0.0