home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_08_09 / 8n09047b < prev    next >
Text File  |  1990-05-16  |  2KB  |  76 lines

  1.  
  2. Listing 3:
  3.  
  4. /* complex hyperbolic sine routine intended to test 
  5.    argument passing and function returns only.  This 
  6.    version passes doubles to a function which obtains
  7.    memory using malloc() and returns pointers to that
  8.    memory.  */ 
  9.  
  10. #include <dos.h>
  11. #include <math.h>
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <time.h>
  15.  
  16. #define BIOS_DATA_SEG   0x40
  17. #define TIMER_DATA      0x6c
  18. #define TICKS_PER_DAY   0x01800B0L
  19.  
  20. long getticks(void);
  21. char *csinh(double, double);
  22.  
  23. main()
  24.  
  25. {
  26.    double x, y, realarg, imagarg;
  27.    char *vlurtnd;
  28.    int ctr;
  29.    long start, end;
  30.  
  31.    start = getticks();
  32.    printf("\n  BEGIN AT CLOCK = %ld", start);
  33.  
  34.    realarg = 3.0;
  35.    imagarg = -2.0;
  36.  
  37.    for(ctr = 1; ctr <= 5000; ++ctr)
  38.  
  39.    {
  40.       vlurtnd = csinh(realarg, imagarg);
  41.       x = *(double*)(vlurtnd);
  42.       y = *((double*)(vlurtnd + 8));
  43.  
  44.       free((void*)vlurtnd);
  45.    }
  46.  
  47.    end = getticks();
  48.  
  49.    printf("\n\n        REAL RESULT = %lG", x);
  50.    printf("        IMAG RESULT = %lG", y);
  51.  
  52.    printf("\n    END AT CLOCK = %ld", end);
  53.    printf("\n\n   ELAPSED TICKS = %ld", end - start);
  54. }
  55.  
  56. char *csinh(double realarg, double imagarg)
  57.  
  58. {
  59.    double outreal, outimag, *pntrreal, *pntrimag;
  60.    char *rtnvlu;
  61.  
  62.    rtnvlu = (char *)malloc(16);
  63.  
  64.    outreal = cos(imagarg) * sinh(realarg);
  65.    outimag = sin(imagarg) * cosh(realarg);
  66.  
  67.    pntrreal = (double*)rtnvlu;
  68.    pntrimag = (double*)(rtnvlu + 8);
  69.  
  70.    *pntrreal = outreal;
  71.    *pntrimag = outimag;
  72.  
  73.    return rtnvlu;
  74. }
  75.  
  76.