- Inherits from:
- Object
- Conforms to:
- DBitArithmetic, DComparable, DDatable, DParsable, DSimpleArithmetic, DTextable
- Declared in:
- DBigInt.h
Object
|
+---DBigInt
Class Description
The big int class implements a number of methods for working with arbitrary large integer numbers.
The class uses the excellent gmp library for the actual calculations.
- Last modified:
- 23-Jul-2006 (DBigInt.h)
Instance Variables
- private void *_value
- the bit integer value
- Constructors
- - (DBigInt *) init
- Initialise to integer zero
- Returns:
- the object
- - (DBigInt *) init :(long) number
- Initialise to a (small) number
- Parameters:
- number - the (small) number
- Returns:
- the object
- - (DBigInt *) init :(const char *) cstring :(int) base
- Initialise with a string
- Parameters:
- cstring - the cstring with the number
base - the base for the number
- Returns:
- the object
- Copy constructor
- - shallowCopy
- Do a shallow copy of the object
- Returns:
- the object
- Deconstructor
- - free
- Free a big integer
- Returns:
- the object
- - (BOOL) isNegative
- Member methods
Check if the big integer is negative
- Returns:
- is it?
- - (BOOL) isZero
- Check if the big integer is zero
- Returns:
- is it ?
- Set methods
- - (DBigInt *) clear
- Set the big integer to zero
- Returns:
- the object
- - (DBigInt *) move :(DBigInt *) other
- Move an other object in this object
- Parameters:
- other - the other object
- Returns:
- this object
- - (DBigInt *) set :(long) number
- Set the big integer with a (small) number
- Parameters:
- number - the (small) number
- Returns:
- the object
- - (BOOL) set :(const char *) cstring :(int) base
- Set the big integer with a text number
- Parameters:
- cstring - the cstring with the number
base - the base of the number (2..36)
- Returns:
- success
- - (DBigInt *) set :(const unsigned char *) number :(unsigned long) length :(BOOL) negative
- Set the big integer with an array of bytes
- Parameters:
- numbers - the number in an array of bytes [0] = least significant (NULL = number 0)
length - the number of bytes in number (length 0 = number 0)
negative - should the number be negative ?
- Returns:
- the object
- Get methods
- - (long) get
- Get the big integer as (small) integer
- Returns:
- the (small) integer
- - (DText *) get :(int) base
- Get the big integer as a text string
- Parameters:
- base - the base for the text string (2..36)
- Returns:
- a (new) text string (or nil)
- - (DData *) toData
- Return the big number as data string (note: keep the negative state seperate)
- Returns:
- the number in a (new) data string (empty for number 0)
- Methods on big integer numbers
- - (DBigInt *) abs
- Absolute the big integer
- Returns:
- the object
- - (DBigInt *) add :(DBigInt *) other
- Add with a big integer
- Parameters:
- other - the big integer
- Returns:
- the object
- - (DBigInt *) add :(DBigInt *) src1 :(DBigInt *) src2
- Add two big integers and store the result in the object
- Parameters:
- src1 - the first big integer
src2 - the second big integer
- Returns:
- the object
- - (DBigInt *) and :(DBigInt *) other
- And with a big integer
- Parameters:
- other - the other big integer
- Returns:
- the object
- - (DBigInt *) and :(DBigInt *) src1 :(DBigInt *) src2
- And two big integers and store the result in the object
- Parameters:
- src1 - the first big integer
src2 - the second big integer
- Returns:
- the object
- - (DBigInt *) com
- One's complement the big integer
- Returns:
- the object
- - (DBigInt *) div :(DBigInt *) other
- Divide with a big integer
- Parameters:
- other - the divider
- Returns:
- the object
- - (DBigInt *) div :(DBigInt *) src1 :(DBigInt *) src2
- Divide two big integers and store the result in the object
- Parameters:
- src1 - the number
src2 - the divider
- Returns:
- the object
- - (DBigInt *) lshift :(unsigned long) shifts
- Left shift the big integer
- Parameters:
- shifts - the number of shifts
- Returns:
- the object
- - (DBigInt *) lshift :(DBigInt *) src :(unsigned long) shifts
- Left shift a big integer and store the result in the object
- Parameters:
- src - the number to be shifted
shifts - the number of shifts
- Returns:
- the object
- - (DBigInt *) mod :(DBigInt *) other
- Determine the module with a big integer
- Parameters:
- other - the divider
- Returns:
- the object
- - (DBigInt *) mod :(DBigInt *) src1 :(DBigInt *) src2
- Determine the module from two big integers and store the result in the object
- Parameters:
- src1 - the number
src2 - the divider
- Returns:
- the object
- - (DBigInt *) mul :(DBigInt *) other
- Multiply with a big integer
- Parameters:
- other - the big integer
- Returns:
- the object
- - (DBigInt *) mul :(DBigInt *) src1 :(DBigInt *) src2
- Multiply two big integers and store the result in the object
- Parameters:
- src1 - the first big integer
src2 - the second big integer
- Returns:
- the object
- - (DBigInt *) negate
- Negate the big integer
- Returns:
- the object
- - (DBigInt *) or :(DBigInt *) other
- Or with a big integer
- Parameters:
- other - the other big integer
- Returns:
- the object
- - (DBigInt *) or :(DBigInt *) src1 :(DBigInt *) src2
- Or two big integers and store the result in the object
- Parameters:
- src1 - the first big integer
src2 - the second big integer
- Returns:
- the object
- - (DBigInt *) rshift :(unsigned long) shifts
- Right shift the big integer
- Parameters:
- shifts - the number of shifts
- Returns:
- the object
- - (DBigInt *) rshift :(DBigInt *) src :(unsigned long) shifts
- Right shift a big integer and store the big integer
- Parameters:
- src - the number to be shifted
shifts - the number of shifts
- Returns:
- the object
- - (DBigInt *) sub :(DBigInt *) other
- Subract with a big integer
- Parameters:
- other - the big integer
- Returns:
- the object
- - (DBigInt *) sub :(DBigInt *) src1 :(DBigInt *) src2
- Subract two big integers and store the result in the object
- Parameters:
- src1 - the first big integer
src2 - the second big integer
- Returns:
- the object
- - (DBigInt *) xor :(DBigInt *) other
- Xor with a big integer
- Parameters:
- other - the other big integer
- Returns:
- the object
- - (DBigInt *) xor :(DBigInt *) src1 :(DBigInt *) src2
- Xor two big integers and store the result in the object
- Parameters:
- src1 - the first big integer
src2 - the second big integer
- Returns:
- the object
- DComparable protocol implementation
- - (int) compare :(DBigInt *) other
- Compare with a big integer
- Parameters:
- other - the other big integer
- Returns:
- the compare result (-1,0,1)
- Textable protocol implementation
- - (DText *) toText
- Convert to a decimal text string
- Returns:
- a (new) text string with the big integer (or nil)
- DParsable protocol implementation
- - (int) fromString :(char **) cstr
- Parse a string for a big integer. Formats:
decimal: [space]*[+-][1..9][0..9]*
hexadecimal: [space]*[+-]0x[0..9a..f]*
octal: [space]*[+-]0[0..7]*
- Parameters:
- cstr - the string to be parsed (moved to the first non-parsable char)
- Returns:
- the result (0,ERANGE,ENODATA)
generated 25-Jul-2006 by ObjcDoc 3.0.0