Ejemplo n.º 1
0
Archivo: parse.c Proyecto: AAAJet/ooc
static void initMath (void)
{	static const struct {
		const char * name;
		function lib;
	} functions [] = {
		{ "sin",   sin },
		{ "cos",   cos },
		{ "tan",   tan },
		{ "asin",  asin },
		{ "acos",  acos },
		{ "atan",  atan },
		{ "sinh",  sinh },
		{ "cosh",  cosh },
		{ "tanh",  tanh },
		{ "exp",   exp },
		{ "log",   log },
		{ "log10", log10 },
		{ "sqrt",  sqrt },
		{ "ceil",  ceil },
		{ "floor", floor },
		{ "abs",   fabs },
	{ 0 }}, * fp = functions;

	while (fp -> name)
		install(table, new(Math(), fp -> name, MATH, fp -> lib)),
		++ fp;
}
Ejemplo n.º 2
0
Relation* aiRelation::generateRelation()
{
	Relation* outputRelation = new Relation;
	outputRelation->A = personA;
	outputRelation->B = personB;

	int randNum = rand()%6;
	outputRelation->relations = (ai_relation)randNum;
	randNum = rand()%7;
	outputRelation->friendship = (ai_friendship)randNum;
	outputRelation->heart = randNum * 20;
	
	int i = 0;
	int sum = 0;
	while (i < Math().min(personA->idNum,personB->idNum))
		sum += (aiSize-i-1);
	sum += Math().abs(personA->idNum,personB->idNum) - 1 + aiSize;
	outputRelation->id = sum;

	//print out
	std::cout << personA->name << " and " << personA->name <<" have a relation: " << outputRelation->relations;
	return outputRelation;
}
Ejemplo n.º 3
0
int main(int argc, char *argv[])
{
	int num;
	char input[10], *temp, hold;
	
	printf("Post-fix calculator. Please enter a number or an operation (+, -, *) "
		   "one per line. Enter '=' to display answer\n");

	while (loop)
	{
		fgets(input, 10, stdin);

		temp = strtok(input, " \n");
		strcpy(input, temp);

		if (strlen(input) > 1)
		{
			num = atoi(input);
			Push(num);
		}
		else
		{
			hold = input[0];

			if (isdigit(hold))
			{
				num = atoi(input);
				Push(num);
			}
			else
			{
				if (hold == '=')
					Answer();
				else
					Math(hold);
			}
		}
	}

	return 0;
}
Ejemplo n.º 4
0
int	User_Program::Execute (int _record)
{
	int stat;
	bool test;

	memset (out_flag, '\0', num_files * sizeof (int));

	stat = 0;
	s = stack [sindex = 1];
	loop = 0;

	if (_record < 0) {
		record++;
	} else {
		record = _record;
	}

	//---- process each command ----

	for (cmd_ptr = command.First (); cmd_ptr; cmd_ptr = command.Next ()) {
		s1 = stack [sindex - 1];

		switch (cmd_ptr->type) {

			case LIMIT:
				if (cmd_ptr->token != EQUALS) {
					exe->Error ("Unrecognized Limit Token = %d (stack=%d)", 
						cmd_ptr->token, command.Record_Index ());
					return (-1);
				}
				cmd_ptr = command.Next ();

				if (!Assign ()) return (-1);
				break;

			case LOGICAL:
				if (cmd_ptr->token == IF || cmd_ptr->token == WHILE) {
					if (s->type == INT_DATA) {
						test = (s->lvalue != 0);
					} else if (s->type == FLOAT_DATA) {
						test = (s->fvalue != 0.0);
					} else if (s->type == STRING_DATA) {
						test = (s->svalue [0] != '\0');
					} else {
						test = false;
					}
					s = stack [sindex = 1];
					if (test) continue;
				}
				cmd_ptr = command [cmd_ptr->value];
				break;

			case RELATION:
				if (!Relation ()) return (-1);
				break;

			case MATH:
				if (!Math ()) return (-1);
				break;

			case FUNCTION:
				if (!Function ()) return (-1);
				break;

			case CONVERT:
				if (!Convert ()) return (-1);
				break;

			case DATETIME:
				if (!Date_Time ()) return (-1);
				break;

			case IN_OUT:
				if (!Input_Output ()) return (-1);
				break;

			case TABLE:
				if (!Table ()) return (-1);
				break;

			case RETURN:
				if (s->type == INT_DATA) {
					stat = s->lvalue;
				} else if (s->type == FLOAT_DATA) {
					stat = (int) s->fvalue;
				}
				return (stat);
				break;

			default:
				if (!Read_Value ()) return (-1);
				break;
		}
	}
	return (stat);
}