home *** CD-ROM | disk | FTP | other *** search
/ Dream 57 / Amiga_Dream_57.iso / Amiga / Programmation / e / Modules / bignume.lha / BigNumE / Examples / add.e next >
Encoding:
Text File  |  1998-05-24  |  1.1 KB  |  54 lines

  1. /*
  2. ** ADD - Add two BigNums
  3. **
  4. ** Author:        Allebrand Brice
  5. ** E translation: Maciej Plewa
  6. */
  7.  
  8. OPT PREPROCESS
  9.  
  10. MODULE    'exec/memory',
  11.         'exec/io',
  12.         'bignum',
  13.         'libraries/bignum',
  14.         'timer',
  15.         'devices/timer'
  16.  
  17. #define    TEMPLATE 'Number1/A, Number2/A'
  18. #define TXT 'Two Numbers !\n'
  19. #define WARN 'Needs BigNum.library 37 !!\n'
  20.  
  21. PROC main()
  22.     DEF tr:PTR TO timerequest, rdargs, opts:PTR TO LONG, aa:PTR TO timeval, bb:PTR TO timeval,
  23.     x:PTR TO bignum, y:PTR TO bignum, z:PTR TO bignum
  24.  
  25.     IF bignumbase:=OpenLibrary('BigNum.library', 37)
  26.         NEW tr, aa, bb
  27.         IF OpenDevice('timer.device', UNIT_MICROHZ, tr, 0)=0
  28.             timerbase:=tr.io.device
  29.             opts:=[0, 0]
  30.             IF rdargs:=ReadArgs(TEMPLATE, opts, 0)
  31.                 x:=BigNumInit()
  32.                 y:=BigNumInit()
  33.                 z:=BigNumInit()
  34.                 BigNumStrToBigNum(x, opts[0])
  35.                 BigNumStrToBigNum(y, opts[1])
  36.                 GetSysTime(aa)
  37.                 BigNumAdd(x,y,z)
  38.                 GetSysTime(bb)
  39.                 SubTime(bb,aa)
  40.                 BigNumPrint(z)
  41.                 PrintF('\n(\d.\d[05] s)\n\n', bb.secs, bb.micro)
  42.                 BigNumFree(3)
  43.                 FreeArgs(rdargs)
  44.             ELSE
  45.                 PrintF(TXT)
  46.             ENDIF
  47.             CloseDevice(tr)
  48.         ENDIF
  49.         CloseLibrary(bignumbase)
  50.     ELSE
  51.         PrintF(WARN)
  52.     ENDIF
  53. ENDPROC
  54.