コード例 #1
0
ファイル: SQF.cpp プロジェクト: mrflay/arma-javascript
// Generate SQF "throw ..." statement
std::string SQF::Throw(const std::string &message) {

	std::string sqf("throw ");

	sqf += SQF::String(message);

	return sqf;
}
コード例 #2
0
ファイル: image_f32.c プロジェクト: versatran01/apriltag
void image_f32_gaussian_blur(image_f32_t *im, double sigma, int ksz)
{
    assert((ksz & 1) == 1); // ksz must be odd.

    // build the kernel.
    float k[ksz];

    // for kernel of length 5:
    // dk[0] = f(-2), dk[1] = f(-1), dk[2] = f(0), dk[3] = f(1), dk[4] = f(2)
    for (int i = 0; i < ksz; i++) {
        int x = -ksz/2 + i;
        float v = exp(-.5*sqf(x / sigma));
        k[i] = v;
    }

    // normalize
    float acc = 0;
    for (int i = 0; i < ksz; i++)
        acc += k[i];

    for (int i = 0; i < ksz; i++)
        k[i] /= acc;

    for (int y = 0; y < im->height; y++) {
        float x[im->stride];
        memcpy(x, &im->buf[y*im->stride], im->stride * sizeof(float));
        convolve(x, &im->buf[y*im->stride], im->width, k, ksz);
    }

    for (int x = 0; x < im->width; x++) {
        float xb[im->height];
        float yb[im->height];

        for (int y = 0; y < im->height; y++)
            xb[y] = im->buf[y*im->stride + x];

        convolve(xb, yb, im->height, k, ksz);

        for (int y = 0; y < im->height; y++)
            im->buf[y*im->stride + x] = yb[y];
    }
}
コード例 #3
0
ファイル: calc.c プロジェクト: dot1q/Misc
double calculate(int numInputTokens, char **inputString)
{
	int i, limit=0;
	double result = 0.0;
	char *s;
	struct DynArr *stack;

	//set up the stack
	stack = createDynArr(20);
	
	printf("testing info! numInputTOkesn: %d\n", numInputTokens);

	// start at 1 to skip the name of the calculator calc
	for(i=1;i < numInputTokens;i++) 
	{
		s = inputString[i];

		// Hint: General algorithm:
		// (1) Check if the string s is in the list of operators.
		//   (1a) If it is, perform corresponding operations.
		//   (1b) Otherwise, check if s is a number.
		//     (1b - I) If s is not a number, produce an error.
		//     (1b - II) If s is a number, push it onto the stack

		if(strcmp(s, "+") == 0){
			add(stack);
			limit = 0; }
		else if(strcmp(s,"-") == 0){
			subtract(stack);
			limit = 0; }
		else if(strcmp(s, "/") == 0){
			divide(stack);
			limit = 0; }
		else if(strcmp(s, "x") == 0){
			multiply(stack);
			limit = 0; }
		else if(strcmp(s, "^") == 0){
			power(stack);
			limit = 0;
			}
		else if(strcmp(s, "^2") == 0){
			square(stack);
			limit = 0;
			}
		else if(strcmp(s, "^3") == 0 ){
			cube(stack);
			limit = 0;
			}
		else if(strcmp(s, "abs") == 0){
			abso(stack);
			limit = 0;
			}
		else if(strcmp(s, "sqrt") == 0){
			sqf(stack);
			limit = 0;
			}
		else if(strcmp(s, "exp") == 0){
			expo(stack);
			limit = 0;
			}
		else if(strcmp(s, "ln") == 0){
			logg(stack);
			limit = 0;
			}
		else if(strcmp(s, "log") == 0){
			logg10(stack);
			limit = 0;
			}
		else 
		{
			if(limit >=2){
				printf("\nLimit has been reached! You did something wrong!\n");
				break;
			}
			//printf("%c is not an operator! converting to a a number!\n",*s);
			int isNum;
			double num = 0;
			isNum = isNumber(s, &num);
			if(isNum == 1){
				//Is infact a number, push to stack
				pushDynArr(stack, num);
				limit++;
				//printf("value %f is now pushed to the statck\n", num);
				printf("\n%f", num);
				
			}else{
				if(strcmp(s, "pi") == 0){
					pushDynArr(stack, 3.144159265);
					printf("\n3.144159265");
					limit++;
				}else if(strcmp(s, "e") == 0){
					pushDynArr(stack, 2.7182818);
					limit++;
					printf("\n2.7182818");
				}else{
					//ignore because it is not a number
					printf("\nPosition %d is not a number, ignoring...\n", i+1);
				}
			}
				//limit is more than 2, this should not happen!
			// Remember to deal with special values ("pi" and "e")
			
		}
	}	//end for 
	
	/* FIXME: You will write this part of the function (2 steps below) 
	 * (1) Check if everything looks OK and produce an error if needed.
	 * (2) Store the final value in result and print it out.
	 */
	if( stack->size > 1){
		//something went wrong
		printf("\nError computing value, check your entry!\n");
	}else{
	result = topDynArr(stack);
	}
	
	return result;
}