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

  1. /*
  2. ** LUCAS - Perform a Lucas Lehmer test.
  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 'Lucas exposant/A'
  18. #define TXT 'I need an exposant !\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.     ret
  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]
  30.             IF rdargs:=ReadArgs(TEMPLATE, opts, 0)
  31.                 GetSysTime(aa)
  32.                 ret:=BigNumLucasLehmer(Val(opts[0]))
  33.                 GetSysTime(bb)
  34.                 SubTime(bb,aa)
  35.                 PrintF('\n(\d.\d[05] s)\n\n', bb.secs, bb.micro)
  36.                 IF ret
  37.                     PrintF('Prime\n')
  38.                 ELSE
  39.                     PrintF('Not Prime\n')
  40.                 ENDIF
  41.                 FreeArgs(rdargs)
  42.             ELSE
  43.                 PrintF(TXT)
  44.             ENDIF
  45.             CloseDevice(tr)
  46.         ENDIF
  47.         CloseLibrary(bignumbase)
  48.     ELSE
  49.         PrintF(WARN)
  50.     ENDIF
  51. ENDPROC
  52.