InfInt operator/(const InfInt& self, const InfInt& other) { bool sign_result= true; if(self.thesign!= other.thesign){ sign_result= false; } InfInt Int1(self); InfInt Int2(other); Int1.thesign= Int2.thesign= true; InfInt quo; InfInt dummy("1"); InfInt dummy2("-1"); while(Int1.thesign== true){ Int1= Int1- Int2; if(Int1.thesign== true){ quo= quo+ dummy; } } if(sign_result== false){ quo= quo* dummy2; } return quo; }
void InsetMathBinom::draw(PainterInfo & pi, int x, int y) const { Dimension const dim = dimension(*pi.base.bv); Dimension const & dim0 = cell(0).dimension(*pi.base.bv); Dimension const & dim1 = cell(1).dimension(*pi.base.bv); // define the binom brackets docstring const bra = kind_ == BRACE ? from_ascii("{") : kind_ == BRACK ? from_ascii("[") : from_ascii("("); docstring const ket = kind_ == BRACE ? from_ascii("}") : kind_ == BRACK ? from_ascii("]") : from_ascii(")"); int m = x + dim.width() / 2; // FIXME: for an unknown reason the cells must be drawn directly // after the StyleChanger and cannot be drawn after the if case if (kind_ == DBINOM) { StyleChanger dummy(pi.base, LM_ST_DISPLAY); cell(0).draw(pi, m - dim0.wid / 2, y - dim0.des - 3 - 5); cell(1).draw(pi, m - dim1.wid / 2, y + dim1.asc + 3 - 5); } else if (kind_ == TBINOM) { StyleChanger dummy(pi.base, LM_ST_SCRIPT); cell(0).draw(pi, m - dim0.wid / 2, y - dim0.des - 3 - 5); cell(1).draw(pi, m - dim1.wid / 2, y + dim1.asc + 3 - 5); } else { FracChanger dummy2(pi.base); cell(0).draw(pi, m - dim0.wid / 2, y - dim0.des - 3 - 5); cell(1).draw(pi, m - dim1.wid / 2, y + dim1.asc + 3 - 5); } // draw the brackets and the marker mathed_draw_deco(pi, x, y - dim.ascent(), dw(dim.height()), dim.height(), bra); mathed_draw_deco(pi, x + dim.width() - dw(dim.height()), y - dim.ascent(), dw(dim.height()), dim.height(), ket); drawMarkers2(pi, x, y); }
int main(){ std::cout << dummy0(three, two) << std::endl; std::cout << dummy1(zero, one) << std::endl; std::cout << dummy2(three, one) << std::endl; return 0; }
int main(int argc, char** argv) { if (argc != 2) return -1; switch (atoi(argv[1])) { case 1: return dummy1(); case 2: return dummy2(); } return -1; }
/** * @param head: The first node of linked list. * @param x: an integer * @return: a ListNode */ ListNode *partition(ListNode *head, int x) { // write your code here ListNode dummy1(0), dummy2(0); ListNode *head1=&dummy1; ListNode *head2=&dummy2; while(head){ if (head->val<x){ head1->next=head; head1=head1->next; } else{ head2->next=head; head2=head2->next; } head=head->next; } head1->next=dummy2.next; head2->next=0; return dummy1.next; }
ListNode* partition(ListNode* head, int x) { ListNode dummy1(0), dummy2(0); ListNode* p1 = &dummy1; ListNode* p2 = &dummy2; ListNode* p = head; while(p){ if (p->val < x){ p1->next = p; p1 = p1->next; } else { p2->next = p; p2 = p2->next; } p = p->next; } p2->next = NULL; p1->next = dummy2.next; return dummy1.next; }
TEST_F(RouterTests, test_valid_registration_route) { Router router; std::unique_ptr<DummyFactory> dummy1(new DummyFactory()); router.addRoute("/dummy1", std::move(dummy1), Router::route_t::EXACT); ASSERT_THROW(router.getHandler("/"), RouterException) << "No catch all registered, access to '/' impossible"; std::unique_ptr<DummyFactory> dummy2(new DummyFactory()); router.addRoute("/dummy2", std::move(dummy2), Router::route_t::CATCH_ALL); router.getHandler("/dummy1"); router.getHandler("/dummy2"); ASSERT_NE(router.getHandler("/"), nullptr) << "A handling factory should be returned"; }
static void dummy(int x) { dummy2(x-1); }
main (int argc, char *argv[]) { int i; float f; double t0, t1; int iters = 1000000000; int seed = 17; srandom (seed); t0 = get_seconds(); for (i=0; i<iters; i++) { f = dummy(); } t1 = get_seconds(); printf ("dummy \t %f ms\n", t1 - t0); srandom (seed); t0 = get_seconds(); for (i=0; i<iters; i++) { f = dummy(); } t1 = get_seconds(); printf ("dummy \t %f ms\n", t1 - t0); srandom (seed); t0 = get_seconds(); for (i=0; i<iters; i++) { f = dummy2(); } t1 = get_seconds(); printf ("dummy2 \t %f ms\n", t1 - t0); srandom (seed); t0 = get_seconds(); for (i=0; i<iters; i++) { f = dummy2(); } t1 = get_seconds(); printf ("dummy2 \t %f ms\n", t1 - t0); srandom (seed); t0 = get_seconds(); for (i=0; i<iters; i++) { f = my_random_double(); } t1 = get_seconds(); printf ("mine \t %f ms\n", t1 - t0); srandom (seed); t0 = get_seconds(); for (i=0; i<iters; i++) { f = my_random_double(); } t1 = get_seconds(); printf ("mine \t %f ms\n", t1 - t0); srandom (seed); t0 = get_seconds(); for (i=0; i<iters; i++) { f = random_float(); } t1 = get_seconds(); printf ("theirs \t %f ms\n", t1 - t0); srandom (seed); t0 = get_seconds(); for (i=0; i<iters; i++) { f = random_float(); } t1 = get_seconds(); printf ("theirs \t %f ms\n", t1 - t0); }
void InsetMathFrac::draw(PainterInfo & pi, int x, int y) const { setPosCache(pi, x, y); Dimension const dim = dimension(*pi.base.bv); Dimension const dim0 = cell(0).dimension(*pi.base.bv); if (kind_ == UNIT || (kind_ == UNITFRAC && nargs() == 3)) { if (nargs() == 1) { ShapeChanger dummy2(pi.base.font, UP_SHAPE); cell(0).draw(pi, x + 1, y); } else if (nargs() == 2) { cell(0).draw(pi, x + 1, y); ShapeChanger dummy2(pi.base.font, UP_SHAPE); cell(1).draw(pi, x + dim0.width() + 5, y); } else { cell(2).draw(pi, x + 1, y); ShapeChanger dummy2(pi.base.font, UP_SHAPE); FracChanger dummy(pi.base); Dimension const dim1 = cell(1).dimension(*pi.base.bv); Dimension const dim2 = cell(2).dimension(*pi.base.bv); int xx = x + dim2.wid + 5; cell(0).draw(pi, xx + 2, y - dim0.des - 5); cell(1).draw(pi, xx + dim0.width() + 5, y + dim1.asc / 2); } } else { FracChanger dummy(pi.base); Dimension const dim1 = cell(1).dimension(*pi.base.bv); int m = x + dim.wid / 2; if (kind_ == NICEFRAC) { cell(0).draw(pi, x + 2, y - dim0.des - 5); cell(1).draw(pi, x + dim0.width() + 5, y + dim1.asc / 2); } else if (kind_ == UNITFRAC) { ShapeChanger dummy2(pi.base.font, UP_SHAPE); cell(0).draw(pi, x + 2, y - dim0.des - 5); cell(1).draw(pi, x + dim0.width() + 5, y + dim1.asc / 2); } else if (kind_ == FRAC || kind_ == ATOP || kind_ == OVER) { cell(0).draw(pi, m - dim0.wid / 2, y - dim0.des - 2 - 5); cell(1).draw(pi, m - dim1.wid / 2, y + dim1.asc + 2 - 5); } else if (kind_ == TFRAC) { // tfrac is in always in text size StyleChanger dummy2(pi.base, LM_ST_SCRIPT); cell(0).draw(pi, m - dim0.wid / 2, y - dim0.des - 2 - 5); cell(1).draw(pi, m - dim1.wid / 2, y + dim1.asc + 2 - 5); } else { // \cfrac and \dfrac are always in display size StyleChanger dummy2(pi.base, LM_ST_DISPLAY); if (kind_ == CFRAC || kind_ == DFRAC) cell(0).draw(pi, m - dim0.wid / 2, y - dim0.des - 2 - 5); else if (kind_ == CFRACLEFT) cell(0).draw(pi, x + 2, y - dim0.des - 2 - 5); else if (kind_ == CFRACRIGHT) cell(0).draw(pi, x + dim.wid - dim0.wid - 2, y - dim0.des - 2 - 5); cell(1).draw(pi, m - dim1.wid / 2, y + dim1.asc + 2 - 5); } } if (kind_ == NICEFRAC || kind_ == UNITFRAC) { // Diag line: int xx = x; if (nargs() == 3) xx += cell(2).dimension(*pi.base.bv).wid + 5; pi.pain.line(xx + dim0.wid, y + dim.des - 2, xx + dim0.wid + 5, y - dim.asc + 2, pi.base.font.color()); } if (kind_ == FRAC || kind_ == CFRAC || kind_ == CFRACLEFT || kind_ == CFRACRIGHT || kind_ == DFRAC || kind_ == TFRAC || kind_ == OVER) pi.pain.line(x + 1, y - 5, x + dim.wid - 2, y - 5, pi.base.font.color()); drawMarkers(pi, x, y); }
void InsetMathFrac::metrics(MetricsInfo & mi, Dimension & dim) const { Dimension dim0, dim1, dim2; if (kind_ == UNIT || (kind_ == UNITFRAC && nargs() == 3)) { if (nargs() == 1) { ShapeChanger dummy2(mi.base.font, UP_SHAPE); cell(0).metrics(mi, dim0); dim.wid = dim0.width()+ 3; dim.asc = dim0.asc; dim.des = dim0.des; } else if (nargs() == 2) { cell(0).metrics(mi, dim0); ShapeChanger dummy2(mi.base.font, UP_SHAPE); cell(1).metrics(mi, dim1); dim.wid = dim0.width() + dim1.wid + 5; dim.asc = max(dim0.asc, dim1.asc); dim.des = max(dim0.des, dim1.des); } else { cell(2).metrics(mi, dim2); ShapeChanger dummy2(mi.base.font, UP_SHAPE); FracChanger dummy(mi.base); cell(0).metrics(mi, dim0); cell(1).metrics(mi, dim1); dim.wid = dim0.width() + dim1.wid + dim2.wid + 10; dim.asc = max(dim2.asc, dim0.height() + 5); dim.des = max(dim2.des, dim1.height() - 5); } } else { // general cell metrics used for \frac FracChanger dummy(mi.base); cell(0).metrics(mi, dim0); cell(1).metrics(mi, dim1); if (nargs() == 3) cell(2).metrics(mi, dim2); // metrics for special fraction types if (kind_ == NICEFRAC) { dim.wid = dim0.width() + dim1.wid + 5; dim.asc = dim0.height() + 5; dim.des = dim1.height() - 5; } else if (kind_ == UNITFRAC) { ShapeChanger dummy2(mi.base.font, UP_SHAPE); dim.wid = dim0.width() + dim1.wid + 5; dim.asc = dim0.height() + 5; dim.des = dim1.height() - 5; } else { if (kind_ == CFRAC || kind_ == CFRACLEFT || kind_ == CFRACRIGHT || kind_ == DFRAC) { // \cfrac and \dfrac are always in display size StyleChanger dummy2(mi.base, LM_ST_DISPLAY); cell(0).metrics(mi, dim0); cell(1).metrics(mi, dim1); } else if (kind_ == TFRAC) { // tfrac is in always in text size StyleChanger dummy2(mi.base, LM_ST_SCRIPT); cell(0).metrics(mi, dim0); cell(1).metrics(mi, dim1); } dim.wid = max(dim0.wid, dim1.wid) + 2; dim.asc = dim0.height() + 2 + 5; dim.des = dim1.height() + 2 - 5; } } metricsMarkers(dim); }
int main(int argc, char **argv) { Signal<int(int)> sig; Test("disconnect non existing"); { bool res; res = sig.disconnect(0); ASSERT(!res); } Test("connect"); size_t id = sig.connect(Util::dummy); Test("single connection: check result"); const int input = 100; auto numVal = sig.emit(input); auto val = sig.results(); ASSERT(numVal == val->size()); ASSERT(val->size() == 1); ASSERT((*val)[0] == Util::dummy(input)); Test("multiple connections: check results"); size_t id2 = sig.connect(dummy2); size_t id3 = sig.connect(Util::dummy); size_t id4 = sig.connect(dummy2); numVal = sig.emit(input); val = sig.results(); ASSERT(numVal == val->size()); ASSERT(val->size() == 4); ASSERT((*val)[0] == Util::dummy(input)); ASSERT((*val)[1] == dummy2(input)); ASSERT((*val)[2] == Util::dummy(input)); ASSERT((*val)[3] == dummy2(input)); Test("multiple connections: ask results again"); auto val2 = sig.results(); ASSERT(numVal == val2->size()); ASSERT(val2->size() == 4); ASSERT((*val2)[0] == Util::dummy(input)); ASSERT((*val2)[1] == dummy2(input)); ASSERT((*val2)[2] == Util::dummy(input)); ASSERT((*val2)[3] == dummy2(input)); Test("disconnections"); { bool res; res = sig.disconnect(id2); ASSERT(res); res = sig.disconnect(id); ASSERT(res); //disconnect again res = sig.disconnect(id); ASSERT(!res); //wrong id res = sig.disconnect(id + 1); ASSERT(!res); } return 0; }
Complex arctanh(Complex c) { Complex dummy1(1+c.x, c.y); Complex dummy2(1-c.x, -c.y); return 0.5*log(dummy1/dummy2); }