1: #include "../h/rt.h"
   2: 
   3: /*
   4:  * x / y - divide y into x.
   5:  */
   6: 
   7: div(nargs, arg2, arg1, arg0)
   8: int nargs;
   9: struct descrip arg2, arg1, arg0;
  10:    {
  11:    register int t1, t2;
  12:    union numeric n1, n2;
  13: 
  14:    SetBound;
  15:    /*
  16:     * x and y must be numbers.
  17:     */
  18:    if ((t1 = cvnum(&arg1, &n1)) == NULL)
  19:       runerr(102, &arg1);
  20:    if ((t2 = cvnum(&arg2, &n2)) == NULL)
  21:       runerr(102, &arg2);
  22: 
  23:    if (t1 == T_LONGINT && t2 == T_LONGINT) {
  24:       /*
  25:        * x and y are both integers, just divide them and return the result.
  26:        */
  27:       if (n2.integer == 0L)
  28:          runerr(201, &arg2);
  29:       mkint(n1.integer / n2.integer, &arg0);
  30:       }
  31:    else {
  32:       /*
  33:        * Either x or y or both is real, convert the real values to integers,
  34:        *  divide them, and return the result.
  35:        */
  36:       if (t1 == T_LONGINT)
  37:          n1.real = n1.integer;
  38:       if (t2 == T_LONGINT)
  39:          n2.real = n2.integer;
  40:       mkreal(n1.real / n2.real, &arg0);
  41:       }
  42:    ClearBound;
  43:    }
  44: 
  45: Opblock(div,2,"/")

Defined functions

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