예제 #1
0
파일: xeq.c 프로젝트: imincik/pkg-grass
int f_eq(int argc, const int *argt, void **args)
{
    CELL *res = args[0];
    int i;

    if (argc < 2)
	return E_ARG_LO;
    if (argc > 2)
	return E_ARG_HI;

    switch (argt[1]) {
    case CELL_TYPE:
	{
	    CELL *arg1 = args[1];
	    CELL *arg2 = args[2];

	    for (i = 0; i < columns; i++) {
		if (IS_NULL_C(&arg1[i]) || IS_NULL_C(&arg2[i]))
		    SET_NULL_C(&res[i]);
		else
		    res[i] = arg1[i] == arg2[i];
	    }
	    return 0;
	}
    case FCELL_TYPE:
	{
	    FCELL *arg1 = args[1];
	    FCELL *arg2 = args[2];

	    for (i = 0; i < columns; i++) {
		if (IS_NULL_F(&arg1[i]) || IS_NULL_F(&arg2[i]))
		    SET_NULL_C(&res[i]);
		else
		    res[i] = arg1[i] == arg2[i];
	    }
	    return 0;
	}
    case DCELL_TYPE:
	{
	    DCELL *arg1 = args[1];
	    DCELL *arg2 = args[2];

	    for (i = 0; i < columns; i++) {
		if (IS_NULL_D(&arg1[i]) || IS_NULL_D(&arg2[i]))
		    SET_NULL_C(&res[i]);
		else
		    res[i] = arg1[i] == arg2[i];
	    }
	    return 0;
	}
    default:
	return E_INV_TYPE;
    }
}
예제 #2
0
파일: xacos.c 프로젝트: imincik/pkg-grass
int f_acos(int argc, const int *argt, void **args)
{
    DCELL *res = args[0];
    DCELL *arg1 = args[1];
    int i;

    if (argc < 1)
	return E_ARG_LO;
    if (argc > 1)
	return E_ARG_HI;

    if (argt[0] != DCELL_TYPE)
	return E_RES_TYPE;

    if (argt[1] != DCELL_TYPE)
	return E_ARG_TYPE;

    for (i = 0; i < columns; i++)
	if (IS_NULL_D(&arg1[i]))
	    SET_NULL_D(&res[i]);
	else {
	    floating_point_exception = 0;
	    res[i] = RADIANS_TO_DEGREES * acos(arg1[i]);
	    if (floating_point_exception)
		SET_NULL_D(&res[i]);
	}

    return 0;
}
예제 #3
0
int f_atan(int argc, const int *argt, void **args)
{
    DCELL *res = args[0];
    DCELL *arg1 = args[1];
    DCELL *arg2;
    int i;

    if (argc < 1)
	return E_ARG_LO;
    if (argc > 2)
	return E_ARG_HI;

    if (argt[0] != DCELL_TYPE)
	return E_RES_TYPE;

    if (argt[1] != DCELL_TYPE)
	return E_ARG_TYPE;

    if (argc > 1 && argt[2] != DCELL_TYPE)
	return E_ARG_TYPE;

    arg2 = (argc > 1) ? args[2] : NULL;

    for (i = 0; i < columns; i++)
	if (IS_NULL_D(&arg1[i]))
	    SET_NULL_D(&res[i]);
	else if (argc > 1 && IS_NULL_D(&arg2[i]))
	    SET_NULL_D(&res[i]);

	else {
	    floating_point_exception = 0;
	    if (argc == 1)
		res[i] = RADIANS_TO_DEGREES * atan(arg1[i]);
	    else {
		res[i] = RADIANS_TO_DEGREES * atan2(arg2[i], arg1[i]);
		if (res[i] < 0)
		    res[i] += 360.0;
	    }
	    if (floating_point_exception)
		SET_NULL_D(&res[i]);
	}

    return 0;
}
예제 #4
0
파일: xdouble.c 프로젝트: imincik/pkg-grass
int f_double(int argc, const int *argt, void **args)
{
    DCELL *res = args[0];
    int i;

    if (argc < 1)
	return E_ARG_LO;
    if (argc > 1)
	return E_ARG_HI;

    if (argt[0] != DCELL_TYPE)
	return E_RES_TYPE;

    switch (argt[1]) {
    case CELL_TYPE:
	{
	    CELL *arg1 = args[1];

	    for (i = 0; i < columns; i++)
		if (IS_NULL_C(&arg1[i]))
		    SET_NULL_D(&res[i]);
		else
		    res[i] = (DCELL) arg1[i];
	    return 0;
	}
    case FCELL_TYPE:
	{
	    FCELL *arg1 = args[1];

	    for (i = 0; i < columns; i++)
		if (IS_NULL_F(&arg1[i]))
		    SET_NULL_D(&res[i]);
		else
		    res[i] = (DCELL) arg1[i];
	    return 0;
	}
    case DCELL_TYPE:
	{
	    DCELL *arg1 = args[1];

	    for (i = 0; i < columns; i++)
		if (IS_NULL_D(&arg1[i]))
		    SET_NULL_D(&res[i]);
		else
		    res[i] = (DCELL) arg1[i];
	    return 0;
	}
    default:
	return E_INV_TYPE;
    }
}
예제 #5
0
파일: xexp.c 프로젝트: GRASS-GIS/grass-ci
int f_exp(int argc, const int *argt, void **args)
{
    DCELL *res = args[0];
    DCELL *arg1 = args[1];
    DCELL *arg2;
    int i;

    if (argc < 1)
	return E_ARG_LO;
    if (argc > 2)
	return E_ARG_HI;

    if (argt[0] != DCELL_TYPE)
	return E_RES_TYPE;

    if (argt[1] != DCELL_TYPE)
	return E_ARG_TYPE;

    arg2 = (argc > 1) ? args[2] : NULL;

    for (i = 0; i < columns; i++)
	if (IS_NULL_D(&arg1[i]))
	    SET_NULL_D(&res[i]);
	else if (argc > 1 && IS_NULL_D(&arg2[i]))
	    SET_NULL_D(&res[i]);
	else if (argc > 1 && arg1[i] < 0 && arg2[i] != ceil(arg2[i]))
	    SET_NULL_D(&res[i]);
	else {
	    floating_point_exception = 0;
	    res[i] = (argc > 1)
		? pow(arg1[i], arg2[i])
		: exp(arg1[i]);
	    if (floating_point_exception)
		SET_NULL_D(&res[i]);
	}

    return 0;
}
예제 #6
0
int f_isnull(int argc, const int *argt, void **args)
{
    int *res = args[0];
    int i;

    if (argc < 1)
	return E_ARG_LO;
    if (argc > 1)
	return E_ARG_HI;

    if (argt[0] != CELL_TYPE)
	return E_RES_TYPE;

    switch (argt[1]) {
    case CELL_TYPE:
	{
	    CELL *arg1 = args[1];

	    for (i = 0; i < columns; i++)
		res[i] = IS_NULL_C(&arg1[i]) ? 1 : 0;
	    return 0;
	}
    case FCELL_TYPE:
	{
	    FCELL *arg1 = args[1];

	    for (i = 0; i < columns; i++)
		res[i] = IS_NULL_F(&arg1[i]) ? 1 : 0;
	    return 0;
	}
    case DCELL_TYPE:
	{
	    DCELL *arg1 = args[1];

	    for (i = 0; i < columns; i++)
		res[i] = IS_NULL_D(&arg1[i]) ? 1 : 0;
	    return 0;
	}
    default:
	return E_INV_TYPE;
    }
}
예제 #7
0
int f_max(int argc, const int *argt, void **args)
{
    int i, j;

    if (argc < 1)
	return E_ARG_LO;

    for (i = 1; i <= argc; i++)
	if (argt[i] != argt[0])
	    return E_ARG_TYPE;

    switch (argt[0]) {
    case CELL_TYPE:
	{
	    CELL *res = args[0];
	    CELL **argz = (CELL **) args;

	    for (i = 0; i < columns; i++) {
		int nul = 0;
		CELL max;

		for (j = 1; j <= argc; j++)
		    if (IS_NULL_C(&argz[j][i]))
			nul = 1;
		    else if (j == 1)
			max = argz[j][i];
		    else if (max < argz[j][i])
			max = argz[j][i];
		if (nul)
		    SET_NULL_C(&res[i]);
		else
		    res[i] = max;
	    }
	    return 0;
	}
    case FCELL_TYPE:
	{
	    FCELL *res = args[0];
	    FCELL **argz = (FCELL **) args;

	    for (i = 0; i < columns; i++) {
		int nul = 0;
		FCELL max;

		for (j = 1; j <= argc; j++)
		    if (IS_NULL_F(&argz[j][i]))
			nul = 1;
		    else if (j == 1)
			max = argz[j][i];
		    else if (max < argz[j][i])
			max = argz[j][i];
		if (nul)
		    SET_NULL_F(&res[i]);
		else
		    res[i] = max;
	    }

	    return 0;
	}
    case DCELL_TYPE:
	{
	    DCELL *res = args[0];
	    DCELL **argz = (DCELL **) args;

	    for (i = 0; i < columns; i++) {
		int nul = 0;
		DCELL max;

		for (j = 1; j <= argc; j++)
		    if (IS_NULL_D(&argz[j][i]))
			nul = 1;
		    else if (j == 1)
			max = argz[j][i];
		    else if (max < argz[j][i])
			max = argz[j][i];
		if (nul)
		    SET_NULL_D(&res[i]);
		else
		    res[i] = max;
	    }

	    return 0;
	}
    default:
	return E_INV_TYPE;
    }
}
예제 #8
0
파일: xmul.c 프로젝트: GRASS-GIS/grass-ci
int f_mul(int argc, const int *argt, void **args)
{
    int i, j;

    if (argc < 1)
	return E_ARG_LO;

    for (i = 1; i <= argc; i++)
	if (argt[i] != argt[0])
	    return E_ARG_TYPE;

    switch (argt[0]) {
    case CELL_TYPE:
	{
	    CELL *res = args[0];
	    CELL **argz = (CELL **) args;

	    for (i = 0; i < columns; i++) {
		res[i] = 1;
		for (j = 1; j <= argc; j++) {
		    if (IS_NULL_C(&argz[j][i])) {
			SET_NULL_C(&res[i]);
			break;
		    }
		    res[i] *= argz[j][i];
		}
	    }
	    return 0;
	}
    case FCELL_TYPE:
	{
	    FCELL *res = args[0];
	    FCELL **argz = (FCELL **) args;

	    for (i = 0; i < columns; i++) {
		res[i] = 1;
		for (j = 1; j <= argc; j++) {
		    if (IS_NULL_F(&argz[j][i])) {
			SET_NULL_F(&res[i]);
			break;
		    }
		    res[i] *= argz[j][i];
		}
	    }
	    return 0;
	}
    case DCELL_TYPE:
	{
	    DCELL *res = args[0];
	    DCELL **argz = (DCELL **) args;

	    for (i = 0; i < columns; i++) {
		res[i] = 1;
		for (j = 1; j <= argc; j++) {
		    if (IS_NULL_D(&argz[j][i])) {
			SET_NULL_D(&res[i]);
			break;
		    }
		    res[i] *= argz[j][i];
		}
	    }
	    return 0;
	}
    default:
	return E_INV_TYPE;
    }
}
예제 #9
0
int f_mode(int argc, const int *argt, void **args)
{
    static double *value;
    static int value_size;
    int size = argc * sizeof(double);
    int i, j;

    if (argc < 1)
	return E_ARG_LO;

    for (i = 1; i <= argc; i++)
	if (argt[i] != argt[0])
	    return E_ARG_TYPE;

    if (size > value_size) {
	value_size = size;
	value = G_realloc(value, value_size);
    }

    switch (argt[argc]) {
    case CELL_TYPE:
	{
	    CELL *res = args[0];
	    CELL **argv = (CELL **) & args[1];

	    for (i = 0; i < columns; i++) {
		int nv = 0;

		for (j = 0; j < argc && !nv; j++) {
		    if (IS_NULL_C(&argv[j][i]))
			nv = 1;
		    else
			value[j] = (double)argv[j][i];
		}

		if (nv)
		    SET_NULL_C(&res[i]);
		else
		    res[i] = (CELL) mode(value, argc);
	    }
	    return 0;
	}
    case FCELL_TYPE:
	{
	    FCELL *res = args[0];
	    FCELL **argv = (FCELL **) & args[1];

	    for (i = 0; i < columns; i++) {
		int nv = 0;

		for (j = 0; j < argc && !nv; j++) {
		    if (IS_NULL_F(&argv[j][i]))
			nv = 1;
		    else
			value[j] = (double)argv[j][i];
		}

		if (nv)
		    SET_NULL_F(&res[i]);
		else
		    res[i] = (FCELL) mode(value, argc);
	    }
	    return 0;
	}
    case DCELL_TYPE:
	{
	    DCELL *res = args[0];
	    DCELL **argv = (DCELL **) & args[1];

	    for (i = 0; i < columns; i++) {
		int nv = 0;

		for (j = 0; j < argc && !nv; j++) {
		    if (IS_NULL_D(&argv[j][i]))
			nv = 1;
		    else
			value[j] = (double)argv[j][i];
		}

		if (nv)
		    SET_NULL_D(&res[i]);
		else
		    res[i] = (DCELL) mode(value, argc);
	    }
	    return 0;
	}
    default:
	return E_INV_TYPE;
    }
}
예제 #10
0
int f_div(int argc, const int *argt, void **args)
{
    int i;

    if (argc < 2)
	return E_ARG_LO;
    if (argc > 2)
	return E_ARG_HI;

    if (argt[1] != argt[0] || argt[2] != argt[0])
	return E_ARG_TYPE;

    switch (argt[0]) {
    case CELL_TYPE:
	{
	    CELL *res = args[0];
	    CELL *arg1 = args[1];
	    CELL *arg2 = args[2];

	    for (i = 0; i < columns; i++) {
		if (IS_NULL_C(&arg1[i]) || IS_NULL_C(&arg2[i]) ||
		    arg2[i] == 0)
		    SET_NULL_C(&res[i]);
		else
		    res[i] = arg1[i] / arg2[i];
	    }
	    return 0;
	}
    case FCELL_TYPE:
	{
	    FCELL *res = args[0];
	    FCELL *arg1 = args[1];
	    FCELL *arg2 = args[2];

	    for (i = 0; i < columns; i++) {
		if (IS_NULL_F(&arg1[i]) || IS_NULL_F(&arg2[i]) ||
		    arg2[i] == 0.0f)
		    SET_NULL_F(&res[i]);
		else {
		    floating_point_exception = 0;
		    res[i] = arg1[i] / arg2[i];
		    if (floating_point_exception)
			SET_NULL_F(&res[i]);
		}
	    }
	    return 0;
	}
    case DCELL_TYPE:
	{
	    DCELL *res = args[0];
	    DCELL *arg1 = args[1];
	    DCELL *arg2 = args[2];

	    for (i = 0; i < columns; i++) {
		if (IS_NULL_D(&arg1[i]) || IS_NULL_D(&arg2[i]) ||
		    arg2[i] == 0.0)
		    SET_NULL_D(&res[i]);
		else {
		    floating_point_exception = 0;
		    res[i] = arg1[i] / arg2[i];
		    if (floating_point_exception)
			SET_NULL_D(&res[i]);
		}
	    }
	    return 0;
	}
    default:
	return E_INV_TYPE;
    }
}