Exemple #1
0
//各項ごとの計算関数
double calc_exec(char operator)
{
	double ret = 0;

	double a = 0;
	double b = 0;

	#ifdef _Debug_enable
		//デバッグ用
		printf("\t\tDebug : calc_exec -> operator = %c\n",operator);
	#endif

	//少なくとも二つ以上スタックに積んであるか確認する
	if(stack_pointer>=1)
	{
		switch(operator)
		{
			case '+' : b = stack_pop(); a = stack_pop(); ret = my_add(a,b); break;
			case '-' : b = stack_pop(); a = stack_pop(); ret = my_sub(a,b); break;
			case '*' : b = stack_pop(); a = stack_pop(); ret = my_mul(a,b); break;
			case '/' : b = stack_pop(); a = stack_pop(); ret = my_div(a,b); break;
		}
	}
	else
	{
		//エラー処理
		printf("\tError occured : calc_exec -> stack_pointer < 1 stack_pointer = %d\n",stack_pointer);
		error_flag++;
		ret = 0;
	}

	return ret;
}
Exemple #2
0
int main ()
{
  int i = 0;
  for (i = 0; i < SIZE; i++)
    x[i] = my_mul ((float) i, 9932.3323);
  foo ();
  return (int)x[0];
}
Exemple #3
0
int foo ()
{
  int i = 0;
#pragma omp simd safelen (16)
  for (i = 0; i < SIZE; i++)
    x[i] = my_mul ((float)i, 9932.3323);
  return (int)x[0];
}
Exemple #4
0
int main()
{
  struct A a;
  int result;

  a.in_var1 = 10;
  a.in_var2 = foo();

  result = my_mul(a.in_var1, a.in_var2);
  printf("%d to the power %d = %d\n", a.in_var1, a.in_var2, result);
  
  return 0;
}
Exemple #5
0
int	my_pow(int a, int b)
{
  int	res;

  res = 1;
  if (b < 0)
  {
    return (-1);
  }
  if (b > 0)
  {
    res = my_mul(a,  my_pow(a, b - 1));
  }
  return (res);
}
Exemple #6
0
void readArguments(char* argv[]) {
	//printf("Your arguments: operator = %s number1 = %s number2 = %s\n",argv[1],argv[2],argv[3]);
	char operator[4];
	char* number_1 = malloc(sizeof(char) * strlen(argv[2]));
	char* number_2 = malloc(sizeof(char) * strlen(argv[2]));
	strcpy(operator,argv[1]);
	strcpy(number_1,argv[2]);
	strcpy(number_2,argv[3]);

	if (strcmp(operator, "add") == 0) {
		my_add(number_1,number_2);
	} else if (strcmp(operator, "sub") == 0) {
		my_sub(number_1,number_2);
	} else if (strcmp(operator, "mul") == 0) {
		my_mul(number_1,number_2);
	} else if (strcmp(operator, "div") == 0) {
		my_div(number_1,number_2);
	} else { //A case which is not possible - except of an invalid argv[1] argument ;)
		exit(EXIT_FAILURE);
	}
}