1: #include "../h/rt.h"
   2: 
   3: /*
   4:  * numcmp - compare two numbers.  Returns -1, 0, 1 for arg1 <, =, > arg2.
   5:  *  arg0 is made into a descriptor for the return value.
   6:  */
   7: 
   8: numcmp(arg1, arg2, arg0)
   9: struct descrip *arg1, *arg2, *arg0;
  10:    {
  11:    register int result;
  12:    union numeric n1, n2;
  13:    int t1, t2;
  14:    /*
  15:     * Be sure that both arg1 and arg2 are numeric.
  16:     */
  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:     *  arg1 and arg2 are both integers, compare them and
  26:     *  create an integer descriptor in arg0
  27:     */
  28: 
  29:           result = 0;
  30:           if (n1.integer < n2.integer) result = -1;
  31:           else if (n1.integer != n2.integer) result = 1;
  32:       mkint(n2.integer, arg0);
  33:       }
  34:    else {
  35: 
  36:    /*
  37:     *  Either arg1 or arg2 is real. Convert the other to a real,
  38:     *  compare them and create a real descriptor in arg0.
  39:     */
  40: 
  41:       if (t1 == T_LONGINT)
  42:          n1.real = n1.integer;
  43:       if (t2 == T_LONGINT)
  44:          n2.real = n2.integer;
  45:           result = 0;
  46:           if (n1.real < n2.real) result = -1;
  47:           else if (n1.real != n2.real) result = 1;
  48:       mkreal(n2.real, arg0);
  49:       }
  50: 
  51:    return (result);             /* return result in r0 */
  52:    }

Defined functions

numcmp defined in line 8; never used
Last modified: 1984-11-18
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 499
Valid CSS Valid XHTML 1.0 Strict