home *** CD-ROM | disk | FTP | other *** search
/ The Best of Mecomp Multimedia 2 / MECOMP-CD-II.iso / amiga / tools / libs / bignum / examples / src / lucas.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-05  |  1.6 KB  |  69 lines

  1. #define __USE_SYSBASE
  2. #include <proto/exec.h>
  3. #include <exec/memory.h>
  4. #include <proto/dos.h>
  5. #include <proto/BigNum.h>
  6. #include <proto/timer.h>
  7. #include <devices/timer.h>
  8. #include <string.h>
  9.  
  10. #define MEM MEMF_FAST|MEMF_CLEAR
  11. #define TEMPLATE "Lucas exposant/N"
  12. #define TXT "I need an exponant !\n"
  13. #define WARN "Needs BigNum.library v37 !!\n"
  14.  
  15. void maine(void)
  16. {
  17.  struct DosLibrary *DOSBase;
  18.  struct ExecBase *SysBase;
  19.  struct Library *BigNumBase;
  20.  struct Library *TimerBase;
  21.  struct timerequest *tr;
  22.  struct timeval aa,bb;
  23.  struct RDArgs *rdargs;
  24.  long opts[2];
  25.  short ret;
  26.  
  27.  SysBase=*((struct ExecBase **)4);
  28.  opts[0]=opts[1]=0;
  29.  if(DOSBase=(struct DosLibrary *)OpenLibrary("dos.library",37))
  30.  {
  31.   if(BigNumBase=OpenLibrary("BigNum.library",37))
  32.   {
  33.    if(tr=(struct timerequest *)AllocVec(sizeof(struct timerequest),MEM))
  34.    {
  35.     if(!(OpenDevice("timer.device",UNIT_MICROHZ,(struct IORequest *)tr,0)))
  36.     {
  37.      TimerBase=(struct Library *)tr->tr_node.io_Device;
  38.      if(rdargs=ReadArgs(TEMPLATE,opts,NULL))
  39.      {
  40.       if(opts[0])
  41.       {
  42.        GetSysTime(&aa);
  43.        ret=BigNumLucasLehmer(*((int *)opts[0]));
  44.        GetSysTime(&bb);
  45.        SubTime(&bb,&aa);
  46.        Printf("\n(%ld.%05ld s)\n\n",bb.tv_secs,bb.tv_micro);
  47.        if(ret)
  48.         PutStr("Prime\n");
  49.        else
  50.         PutStr("Not Prime\n");
  51.       }
  52.       else
  53.        Printf(TXT);
  54.       FreeArgs(rdargs);
  55.      }
  56.      CloseDevice((struct IORequest *)tr);
  57.     }
  58.     else
  59.      PrintFault(IoErr(),NULL);
  60.     FreeVec(tr);
  61.    }  
  62.    CloseLibrary(BigNumBase);
  63.   }
  64.   else
  65.    Printf(WARN);
  66.   CloseLibrary((struct Library *)DOSBase);
  67.  }
  68. }
  69.