void f_angle(void) { double dot, norma, normb; dot = dotprod((sp-1)->u.arr, sp->u.arr); if(dot <= (-INT_MAX + 2)) { pop_2_elems(); if(dot == -INT_MAX) error("angle: cannot calculate the angle between vectors of different sizes.\n"); else error("angle: invalid arg %d.\n", (dot + INT_MAX)); return; } norma = norm((sp-1)->u.arr); if(norma <= (-INT_MAX + 1)) { pop_2_elems(); error("angle: invalid argument 1.\n"); return; } normb = norm(sp->u.arr); if(normb <= (-INT_MAX + 1)) { pop_2_elems(); error("angle: invalid argument 2.\n"); return; } pop_2_elems(); push_real((double)acos( dot / (norma * normb) )); }
void f_norm(void) { double val = norm(sp->u.arr); if(val == (-INT_MAX + 1)) { pop_stack(); error("norm: invalid argument 1.\n"); return; } pop_stack(); push_real(val); }
/* The (Euclidian) distance between two points */ void f_distance(void) { double total = vector_op((sp-1)->u.arr, sp->u.arr, distance_mult); if(total == -INT_MAX) { pop_2_elems(); error("distance: cannot take the distance of vectors of different sizes.\n"); return; } if((total == (-INT_MAX + 1)) || (total == (-INT_MAX + 2))) { pop_2_elems(); error("distance: invalid arg %d.\n", (total + INT_MAX)); return; } pop_2_elems(); push_real((double)sqrt(total)); }
void f_dotprod(void) { double total = vector_op((sp-1)->u.arr, sp->u.arr, dotprod_mult); if(total == -INT_MAX) { pop_2_elems(); error("dotprod: cannot take the dotprod of vectors of different sizes.\n"); return; } if((total == (-INT_MAX + 1)) || (total == (-INT_MAX + 2))) { pop_2_elems(); error("dotprod: invalid arg %d.\n", (total + INT_MAX)); return; } pop_2_elems(); push_real(total); }
void exec_toreal(){ push_real(pop_int()); }
void input_schema(Pschema s, char *attr_name, int spaces, int pretty, FILE *in_file){ // reads a schema and puts it on the top op tstack if(attr_name!=NULL && pretty){ print_spaces(spaces, stdout); fprintf(stdout, "Input record attribute \"%s\"\n",attr_name); } if(pretty){ print_spaces(spaces, stdout); } if(s->type == TY_RECORD || s->type == TY_ARRAY || s->type == TY_ATTR){ int size = get_schema_size(s); int nfields = 0; switch(s->type){ case TY_RECORD:{ if(pretty){ fprintf(stdout,"Input for a record\n"); } Pschema temp = s->child; while(temp){ input_schema(temp->child, temp->id, spaces+1, pretty, in_file); nfields++; temp = temp->brother; } break; } case TY_ARRAY:{ int i; if(pretty){ fprintf(stdout, "Input for an array\n"); } nfields = s->size; for(i=0; i<nfields; i++){ input_schema(s->child, NULL, spaces+1, pretty, in_file); } break; } default: print_schema(s,0); machine_error("TY_ATTR cannot be used in input_schema()."); break; } exec_cat(nfields,size); } else{ switch(s->type){ case TY_INT: { int in = read_int(stdout, in_file, "Insert an integer: ", pretty); push_int(in); break; } case TY_CHAR: { char in = read_char(stdout, in_file, "Insert a char: ", pretty); push_char(in); break; } case TY_REAL: { float in = read_real(stdout, in_file, "Insert a number of type real: ", pretty); push_real(in); break; } case TY_STRING: { char *in = read_string(stdout, in_file, "Insert a string: ", pretty); char *strig_to_store = stringtable_store(in, stringtable); freemem(in, strlen(in) + 1); push_string(strig_to_store); break; } case TY_BOOL: { char in = read_char(stdout, in_file, "Insert a boolean (0 or 1): ", pretty); push_bool(in == '1'); break; } default: {machine_error("Unknown type of schema in input_schema()."); break;} } } }
void exec_rdiv(){ float n, m; n = pop_real(); m = pop_real(); push_real(m/n); }
void exec_rumi(){ push_real(-pop_real()); }
void exec_rtimes(){ float n, m; n = pop_real(); m = pop_real(); push_real(m*n); }
void exec_rminus(){ float n, m; n = pop_real(); m = pop_real(); push_real(m-n); }
void exec_rplus(){ float n, m; n = pop_real(); m = pop_real(); push_real(m+n); }
void exec_ldr(float f){ push_real(f); }
template <> _BASE_API void call_param::push<float>(size_t i, float value) { push_real(i, to_real(value)); }