Example #1
0
integer ADD_ZZ_Z(const integer& a, const integer& b) {
    integer first = a;
    integer second = b;
    integer result;

    if (first.isPositive == second.isPositive) {  // Если знаки равны
        // Знак результата - знак одного из чисел, а модуль - сумма модулей
        result.isPositive = first.isPositive;
        result.module = ADD_NN_N(first.module, second.module);
    } else {  // Если знаки разные
        // Если первое по модулю больше, то знак результата равен знаку первого
        if (COM_NN_D(first.module, second.module) == ordinal::GT) {
            result.isPositive = first.isPositive;
            result.module = SUB_NN_N(first.module, second.module);
        }
        //Если второе по модулю больше, то знак результата равен знаку второго
        if (COM_NN_D(first.module, second.module) == ordinal::LT) {
            result.isPositive = second.isPositive;
            result.module = SUB_NN_N(second.module, first.module);
        }
        // Модуль в обоих случаях равен разнице модулей
        // Иначе результат останется равным 0
    }
    return result;
}
Example #2
0
struct INTEGER SUB_ZZ_Z(struct INTEGER summand1, struct INTEGER summand2)  // result = summand1 + summand2
  {
  struct INTEGER result;
  /* Проверить числа на равенство */
  if (COM_NN_D(ABS_Z_N(summand1), ABS_Z_N(summand2)) == 0)
    {
    /* Числа равны по модулю */
    if (POZ_Z_D(summand1) == POZ_Z_D(summand2))
      /* знаки одинаковы */
      {
      result.natural_part = ADD_NN_N(ABS_Z_N(summand1), ABS_Z_N(summand2));
      result.sign = summand1.sign;
      }
    else
      {
      /* знаки разные */
      result.natural_part.index = 0;
      result.natural_part.number = (int*)malloc( sizeof(int) );
      result.natural_part.number[0] = 0;
      result.sign = 0;
      
      }
    }
  else
    {
    /* Числа не равны */
    if (POZ_Z_D(summand1) == POZ_Z_D(summand2))
      {
      /* Знаки совпадают */
      result.natural_part = ADD_NN_N(ABS_Z_N(summand1), ABS_Z_N(summand2));
      result.sign = POZ_Z_D(summand1);
      }
    else
      {
      /* Знаки разные */
      result.natural_part = SUB_NN_N(ABS_Z_N(summand1), ABS_Z_N(summand2));
      result.sign = POZ_Z_D(summand1);
      }
    }

  return result;
  }
Example #3
0
struct NATURAL MUL_NN_N(struct NATURAL E, struct NATURAL B)
  {
  // Инициализация числа
  struct NATURAL result;
  result.index = ( (E.index * B.index) / 10 > 0) ? (i + j) : (i + j - 1);
  int i;
  for (i = 0; i < result.index; ++i)
    result.number[i] = 0;
  
  for (i = 0; i < B.index; ++i)
    result = ADD_NN_N( result, MUL_ND_N(MUL_Nk_N(E, i), B.number[i]) );
  }