int main(int argc, char *argv[]) { int a, b, c, d; a = int_add(-1, 2); b = int_sub(1, 2); c = int_mul(3, 4); d = int_div(4, -2); return (a + b + c + d) ? 0 : 1; }
int main() { boost::function2<float, int, int> f; f = int_div(); std::cout << f(5, 3) << std::endl; if (f) std::cout << f(5, 3) << std::endl; else std::cout << "f has no target, so it is unsafe to call" << std::endl; f = 0; f = &mul_ints; return 0; }
void mod_exp(BIGINT *x, BIGINT *n, BIGINT *q, BIGINT *z) { BIGINT N, Y, Z, temp, dummy; ELEMENT check; INDEX i; /* initialize variables */ int_copy (n, &N); int_null( &Y); Y.hw[INTMAX] = 1; int_copy (x, &Z); /* Main loop divides N by 2 each step. Repeat until N = 0, and return Y as result. */ check = 0; INTLOOP (i) check |= N.hw[i]; while (check) { /* if N is odd, multiply by extra factor of Y */ if (N.hw[INTMAX] & 1) { /* Y = (Y * Z) % q; */ int_mul (&Y, &Z, &temp); int_div (&temp, q, &dummy, &Y); } int_div2( &N); /* divide N by 2 */ /* Z = (Z * Z) % q; square Z */ int_mul (&Z, &Z, &temp); int_div( &temp, q, &dummy, &Z); check = 0; INTLOOP (i) check |= N.hw[i]; } int_copy (&Y, z); }
int main() { int t1,t2,t3,t4,t5,t6; for(t1 = 0; t1 <= 3; t1++) { for(t2 = max(2*t1-3,0); t2 <= min(t1+1,3); t2++) { for(t3 = t1; t3 <= min(-t2+2*t1+1,3*t2+2,3); t3++) { for(t4 = max(max(int_div(5*t3+3*t2-6+5,6),int_div(5*t1-t2-4+2,3)),max(t2,0)); t4 <= min(int_div(5*t3+3*t2+7,6),int_div(5*t1-t2+4,3),3); t4++) { for(t5 = max(max(max(int_div(1000*t2-2+2,3),250*t4+1),max(int_div(2000*t1-1000*t2-999+2,3),400*t4-200*t2-199)),int_div(1000*t3-1+2,3)); t5 <= min(min(min(400*t4-200*t2+400,500*t1+499),min(int_div(1000*t3+998,3),int_div(1000*t4+1001,3))),1000); t5++) { for(t6 = max(max(int_div(t5+1000*t2+1,2),t5),max(1000*t1-t5,-2*t5+1000*t4+2)); t6 <= min(min(int_div(t5+1000*t2+999,2),2*t5+1),min(1000*t1-t5+999,-2*t5+1000*t4+1001)); t6++) { printf("%d,%d,%d,%d,%d,%d\n", t1,t2,t3,t4,t5,t6); } } } } } } }
static DskJsonValue * create_user_update (User *user) { Game *game = user->base.game; /* width/height in various units, rounded up */ unsigned tile_width = (user->width + TILE_SIZE - 1) / TILE_SIZE; unsigned tile_height = (user->height + TILE_SIZE - 1) / TILE_SIZE; unsigned cell_width = (tile_width + CELL_SIZE * 2 - 2) / CELL_SIZE; unsigned cell_height = (tile_height + CELL_SIZE * 2 - 2) / CELL_SIZE; /* left/upper corner, rounded down */ int min_tile_x = user->base.x - (tile_width+1) / 2; int min_tile_y = user->base.y - (tile_height+1) / 2; int min_cell_x = int_div (min_tile_x, CELL_SIZE); int min_cell_y = int_div (min_tile_y, CELL_SIZE); unsigned alloced = 16; DskJsonValue **elements = dsk_malloc (sizeof (DskJsonValue *) * alloced); unsigned n_elements = 0; unsigned x, y; for (x = 0; x < cell_width; x++) for (y = 0; y < cell_height; y++) { int ucx = x + min_cell_x; /* un-wrapped x, y */ int ucy = y + min_cell_y; int px = (ucx * CELL_SIZE - user->base.x) * TILE_SIZE + user->width / 2 - TILE_SIZE / 2; int py = (ucy * CELL_SIZE - user->base.y) * TILE_SIZE + user->height / 2 - TILE_SIZE / 2; unsigned cx, cy; Cell *cell; /* deal with wrapping (or not) */ if (ucx < 0) { if (!game->wrap) continue; cx = ucx + game->universe_width; } else if ((unsigned) ucx >= game->universe_width) { cx = ucx; if (game->wrap) cx -= game->universe_width; } else cx = ucx; if (ucy < 0) { if (!game->wrap) continue; cy = ucy + game->universe_height; } else if ((unsigned) ucy >= game->universe_height) { cy = ucy; if (game->wrap) cy -= game->universe_height; } else cy = ucy; /* render walls */ if (cy < game->universe_height && cx <= game->universe_width && game->v_walls[cx + cy * game->universe_width]) { /* render vertical wall */ add_wall (&n_elements, &elements, &alloced, px, py, TILE_SIZE, TILE_SIZE * (CELL_SIZE+1)); } if (cy <= game->universe_height && cx < game->universe_width && game->h_walls[cx + cy * game->universe_width]) { /* render horizontal wall */ add_wall (&n_elements, &elements, &alloced, px, py, TILE_SIZE * (CELL_SIZE+1), TILE_SIZE); } if (cx >= game->universe_width || cy >= game->universe_height) continue; cell = game->cells + (game->universe_width * cy + cx); /* render bullets */ Object *object; for (object = cell->objects[OBJECT_TYPE_BULLET]; object; object = object->next_in_cell) { int bx = px + (object->x - cx * CELL_SIZE) * TILE_SIZE + TILE_SIZE / 2; int by = py + (object->y - cy * CELL_SIZE) * TILE_SIZE + TILE_SIZE / 2; add_bullet (&n_elements, &elements, &alloced, bx, by); } /* render dudes */ for (object = cell->objects[OBJECT_TYPE_USER]; object; object = object->next_in_cell) { int bx = px + (object->x - cx * CELL_SIZE) * TILE_SIZE + TILE_SIZE / 2; int by = py + (object->y - cy * CELL_SIZE) * TILE_SIZE + TILE_SIZE / 2; add_user (&n_elements, &elements, &alloced, bx, by, user == (User*) object); } /* render bad guys */ for (object = cell->objects[OBJECT_TYPE_ENEMY]; object; object = object->next_in_cell) { int bx = px + (object->x - cx * CELL_SIZE) * TILE_SIZE + TILE_SIZE / 2; int by = py + (object->y - cy * CELL_SIZE) * TILE_SIZE + TILE_SIZE / 2; add_enemy (&n_elements, &elements, &alloced, bx, by); } /* render generators */ if (cell->generator) { int bx = px + (cell->generator->x - cx * CELL_SIZE) * TILE_SIZE + TILE_SIZE; int by = py + (cell->generator->y - cy * CELL_SIZE) * TILE_SIZE + TILE_SIZE; add_generator (&n_elements, &elements, &alloced, bx, by, user->base.game->latest_update); } } DskJsonValue *rv; rv = dsk_json_value_new_array (n_elements, elements); dsk_free (elements); user->last_update = game->latest_update; return rv; }