home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1998 April / DPPCPRO0498.ISO / April / MathCad / SETUP / DATA.Z / REALSUM.C < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-05  |  1.5 KB  |  42 lines

  1. #include "mcadincl.h"
  2.     
  3.     
  4.     LRESULT realsumFunction(   LPCOMPLEXSCALAR     c,
  5.                                 LPCCOMPLEXSCALAR    a,
  6.                                 LPCCOMPLEXSCALAR    b   );
  7.  
  8.     FUNCTIONINFO    realsum = 
  9.     { 
  10.     "realsum",                          // Name by which mathcad will recognize the function
  11.     "a,b",                              // realsum will be called as realsum(a,b)
  12.     "real sum of scalars a and b",      // description of realsum(a,b)
  13.     (LPCFUNCTION)realsumFunction,       // pointer to the executible code
  14.     COMPLEX_SCALAR,                     // the return type is also a complex scalar
  15.     2,                                  //  the function takes on 2 arguments
  16.     { COMPLEX_SCALAR, COMPLEX_SCALAR}   // both arguments are complex scalars
  17.     };
  18.     
  19.     
  20.     LRESULT realsumFunction(   LPCOMPLEXSCALAR     c,
  21.                                 LPCCOMPLEXSCALAR    a,
  22.                                 LPCCOMPLEXSCALAR    b   )
  23.     {
  24.         
  25.         // first check to make sure
  26.         // a has no imaginary component
  27.         
  28.         if ( a->imag != 0.0 )   
  29.             return MAKELRESULT(1,1);
  30.           
  31.         if ( b->imag != 0.0 )
  32.             return MAKELRESULT(1,2);        
  33.         
  34.         // otherwise, all is well so add a and b
  35.         c->real = a->real + b->real;
  36.         
  37.         
  38.         return 0;               // return 0 to indicate there was no error
  39.             
  40.     }           
  41.     
  42.