Beispiel #1
0
void display_binary(int n_dim, unsigned int tabs,DIFF_CONST mp_limb_t *x) {
     mp_limb_t s;
     unsigned int i,j;
     
     for(i = 0; i < tabs; ++i) printf(" ");
     if (n_dim == 3 && tables__n_atoms[n_dim] == 8) {
	  
	  printf("%d",evaluate_at(x,4));
	  printf("%d",evaluate_at(x,6));
	  printf("%d",evaluate_at(x,1));
	  printf("%d",evaluate_at(x,7));
	  
	  
	  printf("%d",evaluate_at(x,2));
	  printf("%d",evaluate_at(x,3));
	  printf("%d",evaluate_at(x,0));  
	  printf("%d",evaluate_at(x,5));
     } else {
	  s = *x;
	  for (i = 0, j = 0; i < tables__n_atoms[n_dim]; ++i) {
	       if (s & 1) {
		    printf("1");
		    s ^= 1;
	       } else {
		    printf("0");
	       }
	       s >>= 1;
	       if (i == ULONG_BIT - 1) {
		 ++j;
		 s = x[j];
	       }
	  }
     }
}
Beispiel #2
0
/* Used by plot2d/plot3d/fit:
 * Parse an expression that may return a string or may return a constant or may
 * be a dummy function using dummy variables x, y, ...
 * If any dummy variables are present, set (*atptr) to point to an action table
 * corresponding to the parsed expression, and return NULL.
 * Otherwise evaluate the expression and return a string if there is one.
 * The return value "str" and "*atptr" both point to locally-managed memory,
 * which must not be freed by the caller!
 */
char*
string_or_express(struct at_type **atptr)
{
    int i;
    TBOOLEAN has_dummies;

    static char* str = NULL;
    free(str);
    str = NULL;

    if (atptr)
	*atptr = NULL;

    if (END_OF_COMMAND)
	int_error(c_token, "expression expected");

    /* parsing for datablocks */
    if (equals(c_token,"$"))
	return parse_datablock_name();

    if (isstring(c_token)) {
	str = try_to_get_string();
	return str;
    }

    /* parse expression */
    temp_at();

    /* check if any dummy variables are used */
    has_dummies = FALSE;
    for (i = 0; i < at->a_count; i++) {
	enum operators op_index = at->actions[i].index;
	if ( op_index == PUSHD1 || op_index == PUSHD2 || op_index == PUSHD
                || op_index == SUM ) {
	    has_dummies = TRUE;
	    break;
	}
    }

    if (!has_dummies) {
	/* no dummy variables: evaluate expression */
	struct value val;

	evaluate_at(at, &val);
	if (!undefined && val.type == STRING)
	    str = val.v.string_val;
    }

    /* prepare return */
    if (atptr)
	*atptr  = at;
    return str;
}
Beispiel #3
0
/*
 * Called from plot2d.c (get_data) for "plot with table"
 */
TBOOLEAN
tabulate_one_line(double v[MAXDATACOLS], struct value str[MAXDATACOLS], int ncols)
{
    int col;
    FILE *outfile = (table_outfile) ? table_outfile : gpoutfile;
    struct value keep;

    if (table_filter_at) {
	evaluate_inside_using = TRUE;
	evaluate_at(table_filter_at, &keep);
	evaluate_inside_using = FALSE;
	if (undefined || isnan(real(&keep)) || real(&keep) == 0)
	    return FALSE;
    }

    if (table_var == NULL) {
	char sep = (table_sep && *table_sep) ? *table_sep : '\t';
	for (col = 0; col < ncols; col++) {
	    if (str[col].type == STRING)
		fprintf(outfile, " %s", str[col].v.string_val);
	    else
		fprintf(outfile, " %g", v[col]);
	    if (col < ncols-1)
		fprintf(outfile, "%c", sep);
	}
	fprintf(outfile, "\n");
    } else {
	char buf[64]; /* buffer large enough to hold %g + 2 extra chars */
	char sep = (table_sep && *table_sep) ? *table_sep : '\t';
	size_t size = sizeof(buf);
	char *line = (char *) gp_alloc(size, "");
	size_t len = 0;

	line[0] = NUL;
	for (col = 0; col < ncols; col++) {
	    if (str[col].type == STRING) {
		len = strappend(&line, &size, 0, str[col].v.string_val);
	    } else {
		snprintf(buf, sizeof(buf), " %g", v[col]);
		len = strappend(&line, &size, len, buf);
	    }
	    if (col < ncols-1) {
		snprintf(buf, sizeof(buf), " %c", sep);
		len = strappend(&line, &size, len, buf);
	    }
	}
	append_to_datablock(&table_var->udv_value, line);
    }
 
    return TRUE;
}
Beispiel #4
0
void simple__global_init() {
     unsigned long int i,j;

     table_filler__parse();
     /* initialize the inverse of the s3 operation, namely s3_inv */
     for (i = tables__n_atoms[3];i--;)
	  mpn__zero(arr_s3_inv[i - 1]);
     for (i = 0; i < tables__n_atoms[3]; ++i) {
	  if (!mpn__is_zero(arr_s3[i])) {
	       for (j = 0; j < tables__n_atoms[3]; ++j) {
		    if (evaluate_at(arr_s3[i],j)) {
			 mpn__or(arr_exp[i],arr_s3_inv[j]);
		    }
	       }
	  }
     }	   
}
Beispiel #5
0
struct value *
const_express(struct value *valptr)
{
    int tkn = c_token;

    if (END_OF_COMMAND)
	int_error(c_token, "constant expression required");

    /* div - no dummy variables in a constant expression */
    dummy_func = NULL;

    evaluate_at(temp_at(), valptr);	/* run it and send answer back */

    if (undefined) {
	int_error(tkn, "undefined value");
    }
    return (valptr);
}