コード例 #1
0
ファイル: my_div.c プロジェクト: ethanquix/Bistromathique
t_num	main_div(t_num a, t_num b, int base)
{
  t_num	ret;
  int	*i;
  int	*zero;

  zero = malloc(2 * sizeof(int));
  zero[0] = 0;
  zero[1] = -1;
  if (is_equal_zero(a) == 1)
    {
      ret.num = zero;
      ret.type = 1;
      return (ret);
    }
  i = malloc(2 * sizeof(int));
  i[0] = 0;
  i[1] = base;
  if ((a.type == 1 && b.type == 1) || (a.type == -1 && b.type == -1))
    ret.type = 1;
  else
    ret.type = -1;
  ret.num = my_div(a.num, b.num, i);
  return (ret);
}
コード例 #2
0
ファイル: dentaku.c プロジェクト: ainehanta/J2program
//各項ごとの計算関数
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;
}
コード例 #3
0
ファイル: my.c プロジェクト: macroxue/const-pi
void my_divexact(mpz_t r, mpz_t y, mpz_t x)
{
    unsigned long prec = mpz_sizeinbase(y, 2);
    unsigned long prec2 = mpz_sizeinbase(x, 2);
    if (prec >= div_threshold) {
        mpf_set_prec_raw(d1, prec);
        mpf_set_prec_raw(d2, prec);
        mpf_set_z(d1, y);
        mpf_set_z(d2, x);
        mpf_div_2exp(d1, d1, prec);
        mpf_div_2exp(d2, d2, prec2);
        my_div(d2, d1, d2);
        mpf_mul_2exp(d2, d2, prec-prec2);
        mpf_set_d(d1, 0.5);
        mpf_add(d2, d2, d1);
        mpz_set_f(y, d2);
    } else {
        mpz_divexact(y, y, x);
        //mpz_tdiv_q(y, y, x);
    }
}
コード例 #4
0
ファイル: main.c プロジェクト: TheNeikos/bughack
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);
	}
}
コード例 #5
0
ファイル: MyGP.cpp プロジェクト: andersonbr/gpcred
double MyGene::evaluate(MyGP &gp, string id, string className = "", int graphId){


    double returnValue = 0.0;

    if (isFunction()) {
        switch (node->value())
        {
            case SUM:
                returnValue = my_sum(NthMyChild(0)->evaluate(gp, id, className) , NthMyChild(1)->evaluate(gp, id, className));
                break;
            
            case SUB:
                returnValue = my_sub(NthMyChild(0)->evaluate(gp, id, className), NthMyChild(1)->evaluate(gp, id, className));
                break;

            case MULT:
                returnValue = my_mult(NthMyChild(0)->evaluate(gp, id, className), NthMyChild(1)->evaluate(gp, id, className));
                break;

            case DIV:
                returnValue = my_div(NthMyChild(0)->evaluate(gp, id, className),NthMyChild(1)->evaluate(gp, id, className));
                break;

            case LOG:  // log de tree0 na base tree1
                returnValue = my_div(my_log(NthMyChild(0)->evaluate(gp, id, className)), my_log(NthMyChild(1)->evaluate(gp, id, className)))  ;
                break;

            case POW:  // pow de tree0 na base tree1
                returnValue = my_pow(NthMyChild(0)->evaluate(gp, id, className), NthMyChild(1)->evaluate(gp, id, className))  ;
                break;

            default:
                printf("Funcao: %c", node->value());
                GPExitSystem ((char*) "MyGene::evaluate", (char*)"Undefined node value (function).");
        }
    }
    if (isTerminal()) {
        switch(node->value()) {

            case DF_PER_TERM:
                returnValue = 1.0 + my_log(stats->getDFperTerm(id));
                break;

            case DF_PER_CLASS:
                returnValue = 1.0 + my_log(stats->getDFperClass(id, className));
                break;

            case TF_PER_TERM:
                returnValue = 1.0 + my_log(stats->getTFperTerm(id));
                break;

            case TF_PER_CLASS: 
                returnValue = 1.0 + my_log(stats->getTFperClass(id, className)); //bao!
                break;

            case AM:
                returnValue = stats->getAM(id, className);
                break;

            case MAX_AM:
                returnValue = stats->getMaxAM(id);
                break;

            case DOMINANCE:
                returnValue = stats->getDominance(id, className);
                break;

            case MAX_DOMINANCE:
                returnValue = stats->getMaxDominance(id);
                break;

            case PROB_COND:
                //esta igual ao AM! 
                returnValue = my_div(stats->getTFperClass(id, className) , stats->getTFperTerm(id));
                //versao 2:
                //returnValue = ( stats->getTFperClass(id, className)  / ( stats->getSumTF() + 1.0));  //suavizada         
                //returnValue /= ( stats->getSumTFperClass(className) + 1.0) / (stats->getSumTF() + 1.0 );//suavizada
                //versao 3: usada na dissertacao
//                returnValue = stats->getTFperClass(id,className)/ stats->getSumTFperClass(className);

                break;

            case PROB_COND_NEG:
                //returnValue = my_div(stats->getTFperClass(id, className) , stats->getTFperTerm(id));
                returnValue = 1.0 - my_div(stats->getTFperClass(id, className) , stats->getTFperTerm(id));
                break;

            case GINI:
                returnValue = stats->getGini(id);
                break;

            case IG:
                returnValue = stats->getIG(id, className);
                break;

            case MAX_IG:
                returnValue = stats->getMaxIG(id);
                break;

            case OR:
                returnValue = stats->getOR(id, className);
                break;

            case MAX_OR: 
                returnValue = stats->getMaxOR(id);
                break;

            case IDF:
                //returnValue = stats->getIDFclass(id, className);
                returnValue = stats->getIDF(id);
                break;

            case TFIDF:
                returnValue = stats->getTFIDF(id, className);
                break;

            case MAX_TFIDF: 
                returnValue = stats->getMaxTFIDF(id);
                break;

            case TFICF:
                returnValue = stats->getTFICF(id, className);
                break;

            case MAX_TFICF: 
                returnValue = stats->getMaxTFICF(id);
                break;

            case CTD: 
                returnValue = stats->getCTD(id, className);
                break;

            case MAX_CTD: 
                returnValue = stats->getMaxCTD(id);
                break;

            case GSS:
                returnValue = stats->getGSS(id, className);
                break;

            case MAX_GSS: 
                returnValue = stats->getMaxGSS(id);
                break;

            case CHI: 
                returnValue = stats->getCHI(id, className);
                break;

            case MAX_CHI: 
                returnValue = stats->getMaxCHI(id);
                break;

            case CC:  
                returnValue = stats->getCC(id, className);
                break;

            case MAX_CC: 
                returnValue = stats->getMaxCC(id);
                break;

            case CE:
                returnValue = stats->getCE(id);
                break;

            case NEIGHBORHOOD1:
                returnValue = stats->getNeighborhoodSize1(id,className,graphId);
                break;

            case NEIGHBORHOOD2:
                returnValue = stats->getNeighborhoodSize2(id,className,graphId);
                break;

            case NEIGHBORHOOD3:
                returnValue = stats->getNeighborhoodSize3(id,className,graphId);
                break;

            case HUBSCORE:
                returnValue = stats->getHubScore(id, className, graphId);
                break;

            case AUTHORITY:
                returnValue = stats->getAuthority(id, className, graphId);
                break;

            case EIGENVECTOR:
                returnValue = stats->getEigenVectorCentrality(id, className, graphId);
                break;

            case CLOSENESS:
                returnValue = stats->getCloseness(id, className, graphId);
                break;

            case STRENGTH:
                returnValue = stats->getStrength(id, className, graphId);
                break;

            case CONSTRAINT:
                returnValue = stats->getConstraint(id, className, graphId);	
                break;

            case PAGERANK:
                returnValue = stats->getPageRank(id, className, graphId);
                break;

            case BETWEENNESS:
                returnValue = stats->getBetweenness(id, className, graphId);
                break;

            case BIBCOUPLING:
                returnValue = stats->getBibCoupling(id, className, graphId);
                break;

            case COCITATION:
                returnValue = stats->getCoCitation(id, className, graphId);
                break;

            case JACCARDSIMILARITY:
                returnValue = stats->getJaccardSimilarity(id, className, graphId);
                break;

            case DICESIMILARITY:
                returnValue = stats->getDiceSimilarity(id, className, graphId);
                break;

            case INVERSELOGSIMILARITY:
                returnValue = stats->getInverseLogSimilarity(id, className, graphId);
                break;

            case AVGNEIGHBORHOODDEGREE:
                returnValue = stats->getAvgNearstNeighborDegree(id, className, graphId);
                break;
            
            case NUM1:
                returnValue = 1.0;
                break;
 
            case NUM2:
                returnValue = 2.0;
                break;
 
            case NUM3:
                returnValue = 3.0;
                break;

            default:
                cout << "   Terminal: " << node->value() << endl;
                GPExitSystem ((char*)"MyGene::evaluate",(char*) "Undefined node value (terminal).");
        }
    }
    if(isnan(returnValue)){
        cerr<<"Not a number found! Stop it!"<<endl;
        cerr<<"Valor do nodo = " << node->value()<<endl;
        returnValue=0;
        //exit(-1);
    }

    //DEBUG(cout<<"  valor = "<<returnValue <<endl);;
    return returnValue;
}