Class DBigInt

Inherits from:
Object
Conforms to:
DBitArithmetic, DComparable, DDatable, DParsable, DSimpleArithmetic, DTextable
Declared in:
DBigInt.h

Class Hierarchy

    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.

Example:
#include <stdio.h>
#include "ofc/DBigInt.h"

int main(int argc, char *argv[])
{
  DBigInt *nr1 = [DBigInt alloc];
  DBigInt *nr2 = [DBigInt alloc];
  DBigInt *nr3 = [DBigInt new  ];
  DText   *str;

  [nr1 init :1000];                 // Initialise with an integer number
  [nr2 init :"7000" :10];           // Initialise with a string and a base

  [nr2 mul :nr1];                   // nr2 = nr2 * nr1

  [nr3 sub :nr2 :nr1];              // nr3 = nr2 - nr1

  printf("Value (as long):%ld\n", [nr3 get]);

  str = [nr3 get :10];              // Convert to a string, base 10
  printf("Value (as string):%s\n", [str cstring]);

  if ([nr1 compare :nr2] == 0)      // Compare numbers
    printf("Int1 is equal to int2\n");
  else if ([nr1 compare :nr2] < 0)
    printf("Int1 is smaller than int2\n");
  else
    printf("Int1 is greater than int2\n");

  [str free];                       // Cleanup
  [nr3 free];
  [nr2 free];
  [nr1 free];

  return 0;
}
Last modified:
19-Jul-2008 (DBigInt.h)

Instance Variables

private void *_value
the big integer value

Method Index


generated 06-Sep-2008 by ObjcDoc 3.0.0