
Listing 3:

/* complex hyperbolic sine routine intended to test 
   argument passing and function returns only.  This 
   version passes doubles to a function which obtains
   memory using malloc() and returns pointers to that
   memory.  */ 

#include <dos.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define BIOS_DATA_SEG   0x40
#define TIMER_DATA      0x6c
#define TICKS_PER_DAY   0x01800B0L

long getticks(void);
char *csinh(double, double);

main()

{
   double x, y, realarg, imagarg;
   char *vlurtnd;
   int ctr;
   long start, end;

   start = getticks();
   printf("\n  BEGIN AT CLOCK = %ld", start);

   realarg = 3.0;
   imagarg = -2.0;

   for(ctr = 1; ctr <= 5000; ++ctr)

   {
      vlurtnd = csinh(realarg, imagarg);
      x = *(double*)(vlurtnd);
      y = *((double*)(vlurtnd + 8));

      free((void*)vlurtnd);
   }

   end = getticks();

   printf("\n\n        REAL RESULT = %lG", x);
   printf("        IMAG RESULT = %lG", y);

   printf("\n    END AT CLOCK = %ld", end);
   printf("\n\n   ELAPSED TICKS = %ld", end - start);
}

char *csinh(double realarg, double imagarg)

{
   double outreal, outimag, *pntrreal, *pntrimag;
   char *rtnvlu;

   rtnvlu = (char *)malloc(16);

   outreal = cos(imagarg) * sinh(realarg);
   outimag = sin(imagarg) * cosh(realarg);

   pntrreal = (double*)rtnvlu;
   pntrimag = (double*)(rtnvlu + 8);

   *pntrreal = outreal;
   *pntrimag = outimag;

   return rtnvlu;
}

