1: #include "../h/rt.h"
   2: 
   3: /*
   4:  * -x - negate x.
   5:  */
   6: 
   7: neg(nargs, arg1, arg0)
   8: int nargs;
   9: struct descrip arg1, arg0;
  10:    {
  11:    DclSave
  12:    union numeric n;
  13:    long l;
  14: 
  15:    SetBound;
  16:    /*
  17:     * x must be numeric.
  18:     */
  19:    switch (cvnum(&arg1, &n)) {
  20:       case T_LONGINT:
  21:          /*
  22:           * If it's an integer, check for overflow by negating it and
  23:           *  seeing if the negation didn't "work".  Use mkint to
  24:           *  construct the return value.
  25:           */
  26:          l = -n.integer;
  27:          if (n.integer < 0 && l < 0)
  28:             runerr(203, &arg1);
  29:          mkint(l, &arg0);
  30:          break;
  31: 
  32:       case T_REAL:
  33:          /*
  34:           * x is real, just negate it and use mkreal to construct the
  35:           *  return value.
  36:           */
  37:          mkreal(-n.real, &arg0);
  38:          break;
  39: 
  40:       default:
  41:          /*
  42:           * x isn't numeric.
  43:           */
  44:          runerr(102, &arg1);
  45:       }
  46:    ClearBound;
  47:    }
  48: 
  49: Opblock(neg,1,"-")

Defined functions

neg defined in line 7; used 1 times
  • in line 49
Last modified: 1984-11-18
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 582
Valid CSS Valid XHTML 1.0 Strict