// real numeric binary arithmetic functions

void exec_div() {
  int temp;
  int temp2;
  int temp3;
  int temp4;

  temp = MStackArg2Ref();
  temp2 = MStackArg1Ref();

  arenumbersvectors(temp, temp2);

  temp3 = MgetVecSubtype(temp);
  temp4 = MgetVecSubtype(temp2);
  if (temp3 == INTEGERSUBTYPE) {
    if (temp4 == INTEGERSUBTYPE) {
      stack_arg1 =
        make_integer(
          get_integer_val(temp) /
          get_integer_val(temp2));
    }
    else
    if (temp4 == REALSUBTYPE) {
      init_bigfloat_from_integer(bigfloat_temp4, get_integer_val(temp));
      get_real_val(temp2, bigfloat_temp5);
      divide_bigfloat(bigfloat_temp4, bigfloat_temp5, bigfloat_temp6);
      stack_arg1 = make_real(bigfloat_temp6);
    }
    else
      notnumber();
  }
  else
  if (temp3 == REALSUBTYPE) {
    if (temp4 == REALSUBTYPE) {
      get_real_val(temp, bigfloat_temp4);
      get_real_val(temp2, bigfloat_temp5);
      divide_bigfloat(bigfloat_temp4, bigfloat_temp5, bigfloat_temp6);
      stack_arg1 = make_real(bigfloat_temp6);
    }
    else
    if (temp4 == INTEGERSUBTYPE) {
      init_bigfloat_from_integer(bigfloat_temp5, get_integer_val(temp2));
      get_real_val(temp, bigfloat_temp4);
      divide_bigfloat(bigfloat_temp4, bigfloat_temp5, bigfloat_temp6);
      stack_arg1 = make_real(bigfloat_temp6);
    }
    else
      notnumber();
  }
  else
    notnumber();

  MPop();
  MSetStackArg1(stack_arg1);
  MNextInstruction();

  return;
}

void exec_add() {
  int temp;
  int temp2;
  int temp3;
  int temp4;

  temp = MStackArg2Ref();
  temp2 = MStackArg1Ref();

  arenumbersvectors(temp, temp2);

  temp3 = MgetVecSubtype(temp);
  temp4 = MgetVecSubtype(temp2);
  if (temp3 == INTEGERSUBTYPE) {
    if (temp4 == INTEGERSUBTYPE) {
      stack_arg1 =
        make_integer(
          get_integer_val(temp) +
          get_integer_val(temp2));
    }
    else
    if (temp4 == REALSUBTYPE) {
      init_bigfloat_from_integer(bigfloat_temp4, get_integer_val(temp));
      get_real_val(temp2, bigfloat_temp5);
      add_bigfloat(bigfloat_temp4, bigfloat_temp5, bigfloat_temp6);
      stack_arg1 = make_real(bigfloat_temp6);
    }
    else
      notnumber();
  }
  else
  if (temp3 == REALSUBTYPE) {
    if (temp4 == REALSUBTYPE) {
      get_real_val(temp, bigfloat_temp4);
      get_real_val(temp2, bigfloat_temp5);
      add_bigfloat(bigfloat_temp4, bigfloat_temp5, bigfloat_temp6);
      stack_arg1 = make_real(bigfloat_temp6);
    }
    else
    if (temp4 == INTEGERSUBTYPE) {
      init_bigfloat_from_integer(bigfloat_temp5, get_integer_val(temp2));
      get_real_val(temp, bigfloat_temp4);
      add_bigfloat(bigfloat_temp4, bigfloat_temp5, bigfloat_temp6);
      stack_arg1 = make_real(bigfloat_temp6);
    }
    else
      notnumber();
  }
  else
    notnumber();

  MPop();
  MSetStackArg1(stack_arg1);
  MNextInstruction();

  return;
}

void exec_sub() {
  int temp;
  int temp2;
  int temp3;
  int temp4;

  temp = MStackArg2Ref();
  temp2 = MStackArg1Ref();

  arenumbersvectors(temp, temp2);

  temp3 = MgetVecSubtype(temp);
  temp4 = MgetVecSubtype(temp2);
  if (temp3 == INTEGERSUBTYPE) {
    if (temp4 == INTEGERSUBTYPE) {
      stack_arg1 =
        make_integer(
          get_integer_val(temp) -
          get_integer_val(temp2));
    }
    else
    if (temp4 == REALSUBTYPE) {
      init_bigfloat_from_integer(bigfloat_temp4, get_integer_val(temp));
      get_real_val(temp2, bigfloat_temp5);
      subtract_bigfloat(bigfloat_temp4, bigfloat_temp5, bigfloat_temp6);
      stack_arg1 = make_real(bigfloat_temp6);
    }
    else
      notnumber();
  }
  else
  if (temp3 == REALSUBTYPE) {
    if (temp4 == REALSUBTYPE) {
      get_real_val(temp, bigfloat_temp4);
      get_real_val(temp2, bigfloat_temp5);
      subtract_bigfloat(bigfloat_temp4, bigfloat_temp5, bigfloat_temp6);
      stack_arg1 = make_real(bigfloat_temp6);
    }
    else
    if (temp4 == INTEGERSUBTYPE) {
      init_bigfloat_from_integer(bigfloat_temp5, get_integer_val(temp2));
      get_real_val(temp, bigfloat_temp4);
      subtract_bigfloat(bigfloat_temp4, bigfloat_temp5, bigfloat_temp6);
      stack_arg1 = make_real(bigfloat_temp6);
    }
    else
      notnumber();
  }
  else
    notnumber();

  MPop();
  MSetStackArg1(stack_arg1);
  MNextInstruction();

  return;
}

void exec_mult() {
  int temp;
  int temp2;
  int temp3;
  int temp4;

  temp = MStackArg2Ref();
  temp2 = MStackArg1Ref();

  arenumbersvectors(temp, temp2);

  temp3 = MgetVecSubtype(temp);
  temp4 = MgetVecSubtype(temp2);
  if (temp3 == INTEGERSUBTYPE) {
    if (temp4 == INTEGERSUBTYPE) {
      stack_arg1 =
        make_integer(
          get_integer_val(temp) *
          get_integer_val(temp2));
    }
    else
    if (temp4 == REALSUBTYPE) {
      init_bigfloat_from_integer(bigfloat_temp4, get_integer_val(temp));
      get_real_val(temp2, bigfloat_temp5);
      multiply_bigfloat(bigfloat_temp4, bigfloat_temp5, bigfloat_temp6);
      stack_arg1 = make_real(bigfloat_temp6);
    }
    else
      notnumber();
  }
  else
  if (temp3 == REALSUBTYPE) {
    if (temp4 == REALSUBTYPE) {
      get_real_val(temp, bigfloat_temp4);
      get_real_val(temp2, bigfloat_temp5);
      multiply_bigfloat(bigfloat_temp4, bigfloat_temp5, bigfloat_temp6);
      stack_arg1 = make_real(bigfloat_temp6);
    }
    else
    if (temp4 == INTEGERSUBTYPE) {
      init_bigfloat_from_integer(bigfloat_temp5, get_integer_val(temp2));
      get_real_val(temp, bigfloat_temp4);
      multiply_bigfloat(bigfloat_temp4, bigfloat_temp5, bigfloat_temp6);
      stack_arg1 = make_real(bigfloat_temp6);
    }
    else
      notnumber();
  }
  else
    notnumber();

  MPop();
  MSetStackArg1(stack_arg1);
  MNextInstruction();

  return;
}

void exec_eq() {
  int temp;
  int temp2;
  int temp3;
  int temp4;

  temp = MStackArg2Ref();
  temp2 = MStackArg1Ref();

  arenumbersvectors(temp, temp2);

  temp3 = MgetVecSubtype(temp);
  temp4 = MgetVecSubtype(temp2);

  if (temp3 == INTEGERSUBTYPE) {
    if (temp4 == INTEGERSUBTYPE) {
      if (Mintvecref(temp) == Mintvecref(temp2)) {
        MPop();
        MSetStackArg1(Mtrue);
      }
      else {
        MPop();
        MSetStackArg1(Mfalse);
      }
    }
    else
    if (temp4 == REALSUBTYPE) {
      init_bigfloat_from_integer(bigfloat_temp4, get_integer_val(temp));
      get_real_val(temp2, bigfloat_temp5);
      if (is_bigfloat_equal(bigfloat_temp4, bigfloat_temp5)) {
        MPop();
        MSetStackArg1(Mtrue);
      }
      else {
        MPop();
        MSetStackArg1(Mfalse);
      }
    }
    else
      notnumber();
  }
  else
  if (temp3 == REALSUBTYPE) {
    if (temp4 == REALSUBTYPE) {
      get_real_val(temp, bigfloat_temp4);
      get_real_val(temp2, bigfloat_temp5);
      if (is_bigfloat_equal(bigfloat_temp4, bigfloat_temp5)) {
        MPop();
        MSetStackArg1(Mtrue);
      }
      else {
        MPop();
        MSetStackArg1(Mfalse);
      }
    }
    else
    if (temp4 == INTEGERSUBTYPE) {
      get_real_val(temp, bigfloat_temp4);
      init_bigfloat_from_integer(bigfloat_temp5, get_integer_val(temp2));
      if (is_bigfloat_equal(bigfloat_temp4, bigfloat_temp5)) {
        MPop();
        MSetStackArg1(Mtrue);
      }
      else {
        MPop();
        MSetStackArg1(Mfalse);
      }
    }
    else
      notnumber();
  }
  else
    notnumber();

  MNextInstruction();
  return;
}

void exec_lt() {
  int temp;
  int temp2;
  int temp3;
  int temp4;

  temp = MStackArg2Ref();
  temp2 = MStackArg1Ref();

  arenumbersvectors(temp, temp2);

  temp3 = MgetVecSubtype(temp);
  temp4 = MgetVecSubtype(temp2);

  if (temp3 == INTEGERSUBTYPE) {
    if (temp4 == INTEGERSUBTYPE) {
      if (Mintvecref(temp) < Mintvecref(temp2)) {
        MPop();
        MSetStackArg1(Mtrue);
      }
      else {
        MPop();
        MSetStackArg1(Mfalse);
      }
    }
    else
    if (temp4 == REALSUBTYPE) {
      init_bigfloat_from_integer(bigfloat_temp4, get_integer_val(temp));
      get_real_val(temp2, bigfloat_temp5);
      if (less_than_bigfloat(bigfloat_temp4, bigfloat_temp5)) {
        MPop();
        MSetStackArg1(Mtrue);
      }
      else {
        MPop();
        MSetStackArg1(Mfalse);
      }
    }
    else
      notnumber();
  }
  else
  if (temp3 == REALSUBTYPE) {
    if (temp4 == REALSUBTYPE) {
      get_real_val(temp, bigfloat_temp4);
      get_real_val(temp2, bigfloat_temp5);
      if (less_than_bigfloat(bigfloat_temp4, bigfloat_temp5)) {
        MPop();
        MSetStackArg1(Mtrue);
      }
      else {
        MPop();
        MSetStackArg1(Mfalse);
      }
    }
    else
    if (temp4 == INTEGERSUBTYPE) {
      get_real_val(temp, bigfloat_temp4);
      init_bigfloat_from_integer(bigfloat_temp5, get_integer_val(temp2));
      if (less_than_bigfloat(bigfloat_temp4, bigfloat_temp5)) {
        MPop();
        MSetStackArg1(Mtrue);
      }
      else {
        MPop();
        MSetStackArg1(Mfalse);
      }
    }
    else
      notnumber();
  }
  else
    notnumber();

  MNextInstruction();
  return;
}

void exec_le() {
  int temp;
  int temp2;
  int temp3;
  int temp4;

  temp = MStackArg2Ref();
  temp2 = MStackArg1Ref();

  arenumbersvectors(temp, temp2);

  temp3 = MgetVecSubtype(temp);
  temp4 = MgetVecSubtype(temp2);

  if (temp3 == INTEGERSUBTYPE) {
    if (temp4 == INTEGERSUBTYPE) {
      if (Mintvecref(temp) <= Mintvecref(temp2)) {
        MPop();
        MSetStackArg1(Mtrue);
      }
      else {
        MPop();
        MSetStackArg1(Mfalse);
      }
    }
    else
    if (temp4 == REALSUBTYPE) {
      init_bigfloat_from_integer(bigfloat_temp4, get_integer_val(temp));
      get_real_val(temp2, bigfloat_temp5);
      if (less_than_or_equal_bigfloat(bigfloat_temp4, bigfloat_temp5)) {
        MPop();
        MSetStackArg1(Mtrue);
      }
      else {
        MPop();
        MSetStackArg1(Mfalse);
      }
    }
    else
      notnumber();
  }
  else
  if (temp3 == REALSUBTYPE) {
    if (temp4 == REALSUBTYPE) {
      get_real_val(temp, bigfloat_temp4);
      get_real_val(temp2, bigfloat_temp5);
      if (less_than_or_equal_bigfloat(bigfloat_temp4, bigfloat_temp5)) {
        MPop();
        MSetStackArg1(Mtrue);
      }
      else {
        MPop();
        MSetStackArg1(Mfalse);
      }
    }
    else
    if (temp4 == INTEGERSUBTYPE) {
      get_real_val(temp, bigfloat_temp4);
      init_bigfloat_from_integer(bigfloat_temp5, get_integer_val(temp2));
      if (less_than_or_equal_bigfloat(bigfloat_temp4, bigfloat_temp5)) {
        MPop();
        MSetStackArg1(Mtrue);
      }
      else {
        MPop();
        MSetStackArg1(Mfalse);
      }
    }
    else
      notnumber();
  }
  else
    notnumber();

  MNextInstruction();
  return;
}

void exec_gt() {
  int temp;
  int temp2;
  int temp3;
  int temp4;

  temp = MStackArg2Ref();
  temp2 = MStackArg1Ref();

  arenumbersvectors(temp, temp2);

  temp3 = MgetVecSubtype(temp);
  temp4 = MgetVecSubtype(temp2);

  if (temp3 == INTEGERSUBTYPE) {
    if (temp4 == INTEGERSUBTYPE) {
      if (Mintvecref(temp) > Mintvecref(temp2)) {
        MPop();
        MSetStackArg1(Mtrue);
      }
      else {
        MPop();
        MSetStackArg1(Mfalse);
      }
    }
    else
    if (temp4 == REALSUBTYPE) {
      init_bigfloat_from_integer(bigfloat_temp4, get_integer_val(temp));
      get_real_val(temp2, bigfloat_temp5);
      if (greater_than_bigfloat(bigfloat_temp4, bigfloat_temp5)) {
        MPop();
        MSetStackArg1(Mtrue);
      }
      else {
        MPop();
        MSetStackArg1(Mfalse);
      }
    }
    else
      notnumber();
  }
  else
  if (temp3 == REALSUBTYPE) {
    if (temp4 == REALSUBTYPE) {
      get_real_val(temp, bigfloat_temp4);
      get_real_val(temp2, bigfloat_temp5);
      if (greater_than_bigfloat(bigfloat_temp4, bigfloat_temp5)) {
        MPop();
        MSetStackArg1(Mtrue);
      }
      else {
        MPop();
        MSetStackArg1(Mfalse);
      }
    }
    else
    if (temp4 == INTEGERSUBTYPE) {
      get_real_val(temp, bigfloat_temp4);
      init_bigfloat_from_integer(bigfloat_temp5, get_integer_val(temp2));
      if (greater_than_bigfloat(bigfloat_temp4, bigfloat_temp5)) {
        MPop();
        MSetStackArg1(Mtrue);
      }
      else {
        MPop();
        MSetStackArg1(Mfalse);
      }
    }
    else
      notnumber();
  }
  else
    notnumber();

  MNextInstruction();
  return;
}

void exec_ge() {
  int temp;
  int temp2;
  int temp3;
  int temp4;

  temp = MStackArg2Ref();
  temp2 = MStackArg1Ref();

  arenumbersvectors(temp, temp2);

  temp3 = MgetVecSubtype(temp);
  temp4 = MgetVecSubtype(temp2);

  if (temp3 == INTEGERSUBTYPE) {
    if (temp4 == INTEGERSUBTYPE) {
      if (Mintvecref(temp) >= Mintvecref(temp2)) {
        MPop();
        MSetStackArg1(Mtrue);
      }
      else {
        MPop();
        MSetStackArg1(Mfalse);
      }
    }
    else
    if (temp4 == REALSUBTYPE) {
      init_bigfloat_from_integer(bigfloat_temp4, get_integer_val(temp));
      get_real_val(temp2, bigfloat_temp5);
      if (greater_than_or_equal_bigfloat(bigfloat_temp4, bigfloat_temp5)) {
        MPop();
        MSetStackArg1(Mtrue);
      }
      else {
        MPop();
        MSetStackArg1(Mfalse);
      }
    }
    else
      notnumber();
  }
  else
  if (temp3 == REALSUBTYPE) {
    if (temp4 == REALSUBTYPE) {
      get_real_val(temp, bigfloat_temp4);
      get_real_val(temp2, bigfloat_temp5);
      if (greater_than_or_equal_bigfloat(bigfloat_temp4, bigfloat_temp5)) {
        MPop();
        MSetStackArg1(Mtrue);
      }
      else {
        MPop();
        MSetStackArg1(Mfalse);
      }
    }
    else
    if (temp4 == INTEGERSUBTYPE) {
      get_real_val(temp, bigfloat_temp4);
      init_bigfloat_from_integer(bigfloat_temp5, get_integer_val(temp2));
      if (greater_than_or_equal_bigfloat(bigfloat_temp4, bigfloat_temp5)) {
        MPop();
        MSetStackArg1(Mtrue);
      }
      else {
        MPop();
        MSetStackArg1(Mfalse);
      }
    }
    else
      notnumber();
  }
  else
    notnumber();

  MNextInstruction();
  return;
}
