// Returns true if input is not a dheluks string bool not_dheluks(unsigned char *str) { if (strlen((char *)str) < DHELUKS_STR_MIN_SIZE) //must be at least min size return true; if (not_equal(str, HEADER, HEADER_LEN, "Dheluks header not found")) return true; //first HEADER_LEN chars must be header if (not_supported(str[VSN_POSITION])) //must be a supported version return true; if (str[VSN_POSITION] == '0' && not_formatted(str+HEADER_LEN)) return true; //must have formatting according to version spec return false; }
// Decrypts ctxt, stores as an encoded uint8 int decrypt_phrase(dheluks_ctx_t *ctx, dheluks_pkg_t *pkg, dheluks_kys_t *skr, dheluks_txt_t *txt) { uint8_t dig[DIGEST_SIZE]; chacha_poly1305_set_key(&ctx->ciph, skr->sharekey); //set key chacha_poly1305_set_nonce(&ctx->ciph, pkg->nonce); //set nonce chacha_poly1305_decrypt(&ctx->ciph, pkg->csize, txt->plntxt, pkg->cphtxt); //decrypt chacha_poly1305_digest(&ctx->ciph, DIGEST_SIZE, dig); if (not_equal(dig, pkg->digest, DIGEST_SIZE, "Message authentication failed.")) //if the digests aren't equal, return -1; //return an error return 0; }
static void not_compare(void) { switch (readch()) { case '<': not_less(); break; case '>': not_greater(); break; case '=': not_equal(); break; default: unreadch(); (void)fprintf(stderr, "! command is deprecated\n"); break; } }
static void not_compare(void) { switch (readch()) { case '<': not_less(); break; case '>': not_greater(); break; case '=': not_equal(); break; default: unreadch(); bexec(readline()); break; } }
point2<T> mirror( const point2<T>& target, const line2<T>& over ) { // translate point & line to origin line2<T> t_over = translate( over, -over.start_pt( ).x, -over.start_pt( ).y ); point2<T> t_targ = translate( target, -over.start_pt( ).x, -over.start_pt( ).y ); // get translation matrix float length = segment2<T>{ point2<T>{ 0, 0 }, t_over.end_pt( ) }.length( ); length *= length; float matrix[4] = { static_cast<float>( t_over.end_pt( ).x*t_over.end_pt( ).x - t_over.end_pt( ).y*t_over.end_pt( ).y ), static_cast<float>( 2 * t_over.end_pt( ).x * t_over.end_pt( ).y ), static_cast<float>( 2 * t_over.end_pt( ).x * t_over.end_pt( ).y ), static_cast<float>( t_over.end_pt( ).y*t_over.end_pt( ).y - t_over.end_pt( ).x*t_over.end_pt( ).x ) }; if( not_equal( length, 0.f ) ) { for( int i = 0; i < 4; ++i ) { matrix[i] /= length; } } // calculate new point point2f tmp = { ( matrix[0]*static_cast<float>(t_targ.x) + matrix[1]*static_cast<float>(t_targ.y) ), ( matrix[2]*static_cast<float>(t_targ.x) + matrix[3]*static_cast<float>(t_targ.y) ) }; // reduce rounding errors if T is an integer type if( std::numeric_limits<T>::is_integer ) { tmp.x += 0.5f; tmp.y += 0.5f; } // translate back return translate( point2<T>{ static_cast<T>(tmp.x), static_cast<T>(tmp.y) }, over.start_pt( ).x, over.start_pt( ).y ); }
void UpdateState(Node *s) { if (not_equal(s->g, s->rhs)) { if (!s->inClosed) { s->recalcKey(); if (s->inOpen) open->update(s); else { open->add(s); s->inOpen = true; } } else if (!s->inIncons) { s->inIncons = true; incons.push_back(s); } } else { if (s->inOpen) { s->inOpen = false; open->del(s); } } }
int main() { atexit(count_check); { DP dp; assert(null(dp)); DP dp2(std::move(dp)); assert(null(dp2)); dp = std::move(dp2); assert(null(dp)); dp2.reset(nullptr); assert(null(dp2)); assert(equal(dp, dp2)); } { DP dp{new Derived}; assert(not_null(dp)); assert(val_equal(dp, 1, 1)); dp.reset(new Derived{2}); assert(not_null(dp)); assert(val_equal(dp, 2, 2)); dp.reset(nullptr); assert(null(dp)); dp = DP{new Derived{3}}; assert(not_null(dp)); assert(val_equal(dp, 3, 3)); dp = std::move(dp); dp = DP{new Derived}; assert(not_null(dp)); assert(val_equal(dp, 1, 1)); } { BP bp{new Base}, dp{new Derived}; assert(not_null(bp)); assert(not_null(dp)); assert(val_equal(bp)); assert(val_equal(dp, 1, 1)); assert(val_not_equal(bp, dp)); { BP mp{std::move(bp)}; assert(val_equal(mp)); mp = std::move(dp); assert(val_equal(mp, 1, 1)); } bp.reset(new Base); dp.reset(new Derived); DP dp2{new Derived}; assert(val_not_equal(bp, dp)); assert(val_not_equal(bp, dp2)); assert(not_equal(dp, dp2)); } { CP<0> cp0{new Chain<2>}; assert(val_equal(cp0, 2, 2)); cp0 = CP<3>{new Chain<5>}; assert(val_equal(cp0, 5, 5)); cp0 = CP<2>{CP<5>{CP<8>{new Chain<12>}}}; assert(val_equal(cp0, 12, 12)); } { CP<0> cp0; CP<2> cp2; CP<5> cp5; cp5.reset(new Chain<10>); assert(val_equal(cp5, 10, 10)); cp2 = std::move(cp5); assert(val_equal(cp2, 10, 10)); cp0 = std::move(cp2); assert(val_equal(cp0, 10, 10)); } { GP<0, 0> gp00{GP<0,3>{GP<4,3>{GP<4,4>{GP<4,5>{new Grid<5, 5>}}}}}; assert(val_equal(gp00, 5, 5)); } { GP<0, 0> gp00; GP<1, 0> gp10; GP<1, 1> gp11; GP<1, 2> gp12; GP<2, 2> gp22; gp22.reset(new Grid<2, 5>); gp12 = std::move(gp22); gp11 = std::move(gp12); gp10 = std::move(gp11); gp00 = std::move(gp10); assert(val_equal(gp00, 2, 5)); } }
inline bool val_not_equal(const UP<T> &t, const UP<U> &u) { return not_null(t) && not_null(u) && not_equal(t, u) && val_equal(t, t->n, t->m) && !val_equal(t, u->n, u->m) && !val_equal(u, t->n, t->m) && val_equal(u, u->n, u->m); }
/** * \brief Not equal to operator. */ friend bool operator!= (Parent const& lhs, Parent const& rhs) { return not_equal(lhs, rhs); }
int main(void) { int i; int n; int t; int pygen_0_tagF_temp; int pygen_1_tagF_temp; int pygen_0_compF_temp; int pygen_2_tagF_temp; int pygen_1_compF_temp; int pygen_0_projF_temp; int pygen_1_projF_temp; int pygen_2_compF_temp; int pygen_0_injF_temp; int pygen_1_ifexF_temp; int pygen_3_tagF_temp; int pygen_3_compF_temp; int pygen_2_projF_temp; int pygen_3_projF_temp; int pygen_4_compF_temp; int pygen_1_injF_temp; int pygen_0_ifexF_temp; int pygen_4_projF_temp; int pygen_5_projF_temp; int pygen_0_callF_temp; int pygen_2_injF_temp; int pygen_3_ifexF_temp; int pygen_4_tagF_temp; int pygen_5_compF_temp; int pygen_6_projF_temp; int pygen_7_projF_temp; int pygen_6_compF_temp; int pygen_3_injF_temp; int pygen_2_ifexF_temp; int pygen_8_projF_temp; int pygen_9_projF_temp; int pygen_7_compF_temp; int pygen_4_injF_temp; int pygen_2_let_temp; int pygen_5_tagF_temp; int pygen_8_compF_temp; int pygen_10_projF_temp; int pygen_9_compF_temp; int pygen_5_ifexF_temp; int pygen_6_tagF_temp; int pygen_10_compF_temp; int pygen_11_projF_temp; int pygen_11_compF_temp; int pygen_4_ifexF_temp; int pygen_1_callF_temp; int pygen_7_tagF_temp; int pygen_12_compF_temp; int pygen_12_projF_temp; int pygen_13_projF_temp; int pygen_0_addF_temp; int pygen_5_injF_temp; int pygen_7_ifexF_temp; int pygen_8_tagF_temp; int pygen_13_compF_temp; int pygen_14_projF_temp; int pygen_15_projF_temp; int pygen_1_addF_temp; int pygen_6_injF_temp; int pygen_6_ifexF_temp; int pygen_16_projF_temp; int pygen_17_projF_temp; int pygen_2_callF_temp; int pygen_7_injF_temp; int pygen_18_projF_temp; int pygen_0_usubF_temp; int pygen_8_injF_temp; int pygen_0_let_temp; int pygen_9_tagF_temp; int pygen_14_compF_temp; int pygen_19_projF_temp; int pygen_20_projF_temp; int pygen_2_addF_temp; int pygen_9_injF_temp; int pygen_9_ifexF_temp; int pygen_10_tagF_temp; int pygen_15_compF_temp; int pygen_21_projF_temp; int pygen_22_projF_temp; int pygen_3_addF_temp; int pygen_10_injF_temp; int pygen_8_ifexF_temp; int pygen_23_projF_temp; int pygen_24_projF_temp; int pygen_3_callF_temp; int pygen_11_injF_temp; int pygen_12_injF_temp; int pygen_1_let_temp; int pygen_11_tagF_temp; int pygen_16_compF_temp; int pygen_25_projF_temp; int pygen_26_projF_temp; int pygen_4_addF_temp; int pygen_13_injF_temp; int pygen_11_ifexF_temp; int pygen_12_tagF_temp; int pygen_17_compF_temp; int pygen_27_projF_temp; int pygen_28_projF_temp; int pygen_5_addF_temp; int pygen_14_injF_temp; int pygen_10_ifexF_temp; int pygen_29_projF_temp; int pygen_30_projF_temp; int pygen_4_callF_temp; int pygen_15_injF_temp; i = inject_int(0); n = input_int(); t = inject_int(0); pygen_0_tagF_temp = tag(i); pygen_1_tagF_temp = tag(n); pygen_0_compF_temp = (pygen_0_tagF_temp == pygen_1_tagF_temp); if (pygen_0_compF_temp) { pygen_2_tagF_temp = tag(i); pygen_1_compF_temp = (pygen_2_tagF_temp == 0); if (pygen_1_compF_temp) { pygen_0_projF_temp = project_int(i); pygen_1_projF_temp = project_int(n); pygen_2_compF_temp = (pygen_0_projF_temp != pygen_1_projF_temp); pygen_0_injF_temp = inject_bool(pygen_2_compF_temp); pygen_1_ifexF_temp = pygen_0_injF_temp; } else { pygen_3_tagF_temp = tag(i); pygen_3_compF_temp = (pygen_3_tagF_temp == 1); if (pygen_3_compF_temp) { pygen_2_projF_temp = project_bool(i); pygen_3_projF_temp = project_bool(n); pygen_4_compF_temp = (pygen_2_projF_temp != pygen_3_projF_temp); pygen_1_injF_temp = inject_bool(pygen_4_compF_temp); pygen_0_ifexF_temp = pygen_1_injF_temp; } else { pygen_4_projF_temp = project_big(i); pygen_5_projF_temp = project_big(n); pygen_0_callF_temp = not_equal(pygen_4_projF_temp, pygen_5_projF_temp); pygen_2_injF_temp = inject_bool(pygen_0_callF_temp); pygen_0_ifexF_temp = pygen_2_injF_temp; } pygen_1_ifexF_temp = pygen_0_ifexF_temp; } pygen_3_ifexF_temp = pygen_1_ifexF_temp; } else { pygen_4_tagF_temp = tag(i); pygen_5_compF_temp = (pygen_4_tagF_temp == 0); if (pygen_5_compF_temp) { pygen_6_projF_temp = project_int(i); pygen_7_projF_temp = project_bool(n); pygen_6_compF_temp = (pygen_6_projF_temp != pygen_7_projF_temp); pygen_3_injF_temp = inject_bool(pygen_6_compF_temp); pygen_2_ifexF_temp = pygen_3_injF_temp; } else { pygen_8_projF_temp = project_bool(i); pygen_9_projF_temp = project_int(n); pygen_7_compF_temp = (pygen_8_projF_temp != pygen_9_projF_temp); pygen_4_injF_temp = inject_bool(pygen_7_compF_temp); pygen_2_ifexF_temp = pygen_4_injF_temp; } pygen_3_ifexF_temp = pygen_2_ifexF_temp; } pygen_2_let_temp = pygen_3_ifexF_temp; pygen_5_tagF_temp = tag(pygen_2_let_temp); pygen_8_compF_temp = (pygen_5_tagF_temp == 0); if (pygen_8_compF_temp) { pygen_10_projF_temp = project_int(pygen_2_let_temp); pygen_9_compF_temp = (0 != pygen_10_projF_temp); pygen_5_ifexF_temp = pygen_9_compF_temp; } else { pygen_6_tagF_temp = tag(pygen_2_let_temp); pygen_10_compF_temp = (pygen_6_tagF_temp == 1); if (pygen_10_compF_temp) { pygen_11_projF_temp = project_bool(pygen_2_let_temp); pygen_11_compF_temp = (0 != pygen_11_projF_temp); pygen_4_ifexF_temp = pygen_11_compF_temp; } else { pygen_1_callF_temp = is_true(pygen_2_let_temp); pygen_4_ifexF_temp = pygen_1_callF_temp; } pygen_5_ifexF_temp = pygen_4_ifexF_temp; } while (pygen_5_ifexF_temp) { pygen_7_tagF_temp = tag(t); pygen_12_compF_temp = (pygen_7_tagF_temp == 0); if (pygen_12_compF_temp) { pygen_12_projF_temp = project_int(t); pygen_13_projF_temp = project_int(i); pygen_0_addF_temp = (pygen_12_projF_temp + pygen_13_projF_temp); pygen_5_injF_temp = inject_int(pygen_0_addF_temp); pygen_7_ifexF_temp = pygen_5_injF_temp; } else { pygen_8_tagF_temp = tag(t); pygen_13_compF_temp = (pygen_8_tagF_temp == 1); if (pygen_13_compF_temp) { pygen_14_projF_temp = project_bool(t); pygen_15_projF_temp = project_bool(i); pygen_1_addF_temp = (pygen_14_projF_temp + pygen_15_projF_temp); pygen_6_injF_temp = inject_int(pygen_1_addF_temp); pygen_6_ifexF_temp = pygen_6_injF_temp; } else { pygen_16_projF_temp = project_big(t); pygen_17_projF_temp = project_big(i); pygen_2_callF_temp = add(pygen_16_projF_temp, pygen_17_projF_temp); pygen_7_injF_temp = inject_big(pygen_2_callF_temp); pygen_6_ifexF_temp = pygen_7_injF_temp; } pygen_7_ifexF_temp = pygen_6_ifexF_temp; } t = pygen_7_ifexF_temp; pygen_18_projF_temp = project_int(i); pygen_0_usubF_temp = -(pygen_18_projF_temp); pygen_8_injF_temp = inject_int(pygen_0_usubF_temp); pygen_0_let_temp = pygen_8_injF_temp; pygen_9_tagF_temp = tag(pygen_0_let_temp); pygen_14_compF_temp = (pygen_9_tagF_temp == 0); if (pygen_14_compF_temp) { pygen_19_projF_temp = project_int(pygen_0_let_temp); pygen_20_projF_temp = project_int(t); pygen_2_addF_temp = (pygen_19_projF_temp + pygen_20_projF_temp); pygen_9_injF_temp = inject_int(pygen_2_addF_temp); pygen_9_ifexF_temp = pygen_9_injF_temp; } else { pygen_10_tagF_temp = tag(pygen_0_let_temp); pygen_15_compF_temp = (pygen_10_tagF_temp == 1); if (pygen_15_compF_temp) { pygen_21_projF_temp = project_bool(pygen_0_let_temp); pygen_22_projF_temp = project_bool(t); pygen_3_addF_temp = (pygen_21_projF_temp + pygen_22_projF_temp); pygen_10_injF_temp = inject_int(pygen_3_addF_temp); pygen_8_ifexF_temp = pygen_10_injF_temp; } else { pygen_23_projF_temp = project_big(pygen_0_let_temp); pygen_24_projF_temp = project_big(t); pygen_3_callF_temp = add(pygen_23_projF_temp, pygen_24_projF_temp); pygen_11_injF_temp = inject_big(pygen_3_callF_temp); pygen_8_ifexF_temp = pygen_11_injF_temp; } pygen_9_ifexF_temp = pygen_8_ifexF_temp; } t = pygen_9_ifexF_temp; pygen_12_injF_temp = inject_int(1); pygen_1_let_temp = pygen_12_injF_temp; pygen_11_tagF_temp = tag(i); pygen_16_compF_temp = (pygen_11_tagF_temp == 0); if (pygen_16_compF_temp) { pygen_25_projF_temp = project_int(i); pygen_26_projF_temp = project_int(pygen_1_let_temp); pygen_4_addF_temp = (pygen_25_projF_temp + pygen_26_projF_temp); pygen_13_injF_temp = inject_int(pygen_4_addF_temp); pygen_11_ifexF_temp = pygen_13_injF_temp; } else { pygen_12_tagF_temp = tag(i); pygen_17_compF_temp = (pygen_12_tagF_temp == 1); if (pygen_17_compF_temp) { pygen_27_projF_temp = project_bool(i); pygen_28_projF_temp = project_bool(pygen_1_let_temp); pygen_5_addF_temp = (pygen_27_projF_temp + pygen_28_projF_temp); pygen_14_injF_temp = inject_int(pygen_5_addF_temp); pygen_10_ifexF_temp = pygen_14_injF_temp; } else { pygen_29_projF_temp = project_big(i); pygen_30_projF_temp = project_big(pygen_1_let_temp); pygen_4_callF_temp = add(pygen_29_projF_temp, pygen_30_projF_temp); pygen_15_injF_temp = inject_big(pygen_4_callF_temp); pygen_10_ifexF_temp = pygen_15_injF_temp; } pygen_11_ifexF_temp = pygen_10_ifexF_temp; } i = pygen_11_ifexF_temp; pygen_0_tagF_temp = tag(i); pygen_1_tagF_temp = tag(n); pygen_0_compF_temp = (pygen_0_tagF_temp == pygen_1_tagF_temp); if (pygen_0_compF_temp) { pygen_2_tagF_temp = tag(i); pygen_1_compF_temp = (pygen_2_tagF_temp == 0); if (pygen_1_compF_temp) { pygen_0_projF_temp = project_int(i); pygen_1_projF_temp = project_int(n); pygen_2_compF_temp = (pygen_0_projF_temp != pygen_1_projF_temp); pygen_0_injF_temp = inject_bool(pygen_2_compF_temp); pygen_1_ifexF_temp = pygen_0_injF_temp; } else { pygen_3_tagF_temp = tag(i); pygen_3_compF_temp = (pygen_3_tagF_temp == 1); if (pygen_3_compF_temp) { pygen_2_projF_temp = project_bool(i); pygen_3_projF_temp = project_bool(n); pygen_4_compF_temp = (pygen_2_projF_temp != pygen_3_projF_temp); pygen_1_injF_temp = inject_bool(pygen_4_compF_temp); pygen_0_ifexF_temp = pygen_1_injF_temp; } else { pygen_4_projF_temp = project_big(i); pygen_5_projF_temp = project_big(n); pygen_0_callF_temp = not_equal(pygen_4_projF_temp, pygen_5_projF_temp); pygen_2_injF_temp = inject_bool(pygen_0_callF_temp); pygen_0_ifexF_temp = pygen_2_injF_temp; } pygen_1_ifexF_temp = pygen_0_ifexF_temp; } pygen_3_ifexF_temp = pygen_1_ifexF_temp; } else { pygen_4_tagF_temp = tag(i); pygen_5_compF_temp = (pygen_4_tagF_temp == 0); if (pygen_5_compF_temp) { pygen_6_projF_temp = project_int(i); pygen_7_projF_temp = project_bool(n); pygen_6_compF_temp = (pygen_6_projF_temp != pygen_7_projF_temp); pygen_3_injF_temp = inject_bool(pygen_6_compF_temp); pygen_2_ifexF_temp = pygen_3_injF_temp; } else { pygen_8_projF_temp = project_bool(i); pygen_9_projF_temp = project_int(n); pygen_7_compF_temp = (pygen_8_projF_temp != pygen_9_projF_temp); pygen_4_injF_temp = inject_bool(pygen_7_compF_temp); pygen_2_ifexF_temp = pygen_4_injF_temp; } pygen_3_ifexF_temp = pygen_2_ifexF_temp; } pygen_2_let_temp = pygen_3_ifexF_temp; pygen_5_tagF_temp = tag(pygen_2_let_temp); pygen_8_compF_temp = (pygen_5_tagF_temp == 0); if (pygen_8_compF_temp) { pygen_10_projF_temp = project_int(pygen_2_let_temp); pygen_9_compF_temp = (0 != pygen_10_projF_temp); pygen_5_ifexF_temp = pygen_9_compF_temp; } else { pygen_6_tagF_temp = tag(pygen_2_let_temp); pygen_10_compF_temp = (pygen_6_tagF_temp == 1); if (pygen_10_compF_temp) { pygen_11_projF_temp = project_bool(pygen_2_let_temp); pygen_11_compF_temp = (0 != pygen_11_projF_temp); pygen_4_ifexF_temp = pygen_11_compF_temp; } else { pygen_1_callF_temp = is_true(pygen_2_let_temp); pygen_4_ifexF_temp = pygen_1_callF_temp; } pygen_5_ifexF_temp = pygen_4_ifexF_temp; } } print_any(t); }
bool intersect(const float& x1, const float& y1, const float& x2, const float& y2, const float& x3, const float& y3, const float& x4, const float& y4, float& ix, float& iy) { float ax = x2 - x1; float bx = x3 - x4; float lowerx; float upperx; float uppery; float lowery; if (ax < float(0.0)) { lowerx = x2; upperx = x1; } else { upperx = x2; lowerx = x1; } if (bx > float(0.0)) { if ((upperx < x4) || (x3 < lowerx)) return false; } else if ((upperx < x3) || (x4 < lowerx)) return false; float ay = y2 - y1; float by = y3 - y4; if (ay < float(0.0)) { lowery = y2; uppery = y1; } else { uppery = y2; lowery = y1; } if (by > float(0.0)) { if ((uppery < y4) || (y3 < lowery)) return false; } else if ((uppery < y3) || (y4 < lowery)) return false; float cx = x1 - x3; float cy = y1 - y3; float d = (by * cx) - (bx * cy); float f = (ay * bx) - (ax * by); if (f > float(0.0)) { if ((d < float(0.0)) || (d > f)) return false; } else if ((d > float(0.0)) || (d < f)) return false; float e = (ax * cy) - (ay * cx); if (f > float(0.0)) { if ((e < float(0.0)) || (e > f)) return false; } else if ((e > float(0.0)) || (e < f)) return false; float ratio = (ax * -by) - (ay * -bx); if (not_equal(ratio,float(0.0))) { ratio = ((cy * -bx) - (cx * -by)) / ratio; ix = x1 + (ratio * ax); iy = y1 + (ratio * ay); } else { if (is_equal((ax * -cy),(-cx * ay))) { ix = x3; iy = y3; } else { ix = x4; iy = y4; } } return true; }
void cover_sc_bit() { sc_bit bdef; sc_bit bf(false); sc_bit bt(true); sc_bit b0(0); sc_bit b1(1); try { sc_bit foo(2); } catch (sc_report) { cout << "Caught exception for sc_bit(2)\n"; } sc_bit bc0('0'); sc_bit bc1('1'); try { sc_bit foo('2'); } catch (sc_report) { cout << "Caught exception for sc_bit('2')\n"; } sc_bit blc0(sc_logic('0')); sc_bit blc1(sc_logic('1')); sc_bit blcx(sc_logic('X')); sc_bit bcop(bt); cout << bdef << bf << bt << b0 << b1 << bc0 << bc1 << blc0 << blc1 << blcx << bcop << endl; sc_bit b; b = bt; sc_assert(b); b = 0; sc_assert(!b); b = true; sc_assert(b.to_bool()); b = '0'; sc_assert(!b.to_bool()); b = sc_logic('1'); sc_assert(b.to_char() == '1'); b = bf; sc_assert(~b); b |= bt; sc_assert(b); b &= bf; sc_assert(!b); b |= 1; sc_assert(b); b &= 0; sc_assert(!b); b |= '1'; sc_assert(b); b &= '0'; sc_assert(!b); b |= true; sc_assert(b); b &= false; sc_assert(!b); b ^= bt; sc_assert(b); b ^= 1; sc_assert(!b); b ^= '1'; sc_assert(b); b ^= true; sc_assert(!b); sc_assert(b == bf); sc_assert(b == 0); sc_assert(b == '0'); sc_assert(b == false); b = 1; sc_assert(b == bt); sc_assert(b == 1); sc_assert(b == '1'); sc_assert(b == true); sc_assert(1 == b); sc_assert('1' == b); sc_assert(true == b); sc_assert(equal(b, bt)); sc_assert(equal(b, 1)); sc_assert(equal(b, '1')); sc_assert(equal(b, true)); sc_assert(equal(1, b)); sc_assert(equal('1', b)); sc_assert(equal(true, b)); b = 0; sc_assert(b != bt); sc_assert(b != 1); sc_assert(b != '1'); sc_assert(b != true); sc_assert(1 != b); sc_assert('1' != b); sc_assert(true != b); sc_assert(not_equal(b, bt)); sc_assert(not_equal(b, 1)); sc_assert(not_equal(b, '1')); sc_assert(not_equal(b, true)); sc_assert(not_equal(1, b)); sc_assert(not_equal('1', b)); sc_assert(not_equal(true, b)); // the following assertion is incorrect, because the b_not() method // is destructive, i.e., it implements something like b ~= void. /// sc_assert(b == b_not(b.b_not())); b.b_not(); sc_assert(b); sc_bit bx; b_not(bx, b0); sc_assert(bx); b_not(bx, b1); sc_assert(!bx); cout << (b0|b0) << (b0|b1) << (b1|b0) << (b1|b1) << endl; cout << (b0&b0) << (b0&b1) << (b1&b0) << (b1&b1) << endl; cout << (b0^b0) << (b0^b1) << (b1^b0) << (b1^b1) << endl; cout << (b0|0) << (b0|1) << (b1|0) << (b1|1) << endl; cout << (b0&0) << (b0&1) << (b1&0) << (b1&1) << endl; cout << (b0^0) << (b0^1) << (b1^0) << (b1^1) << endl; cout << (b0|'0') << (b0|'1') << (b1|'0') << (b1|'1') << endl; cout << (b0&'0') << (b0&'1') << (b1&'0') << (b1&'1') << endl; cout << (b0^'0') << (b0^'1') << (b1^'0') << (b1^'1') << endl; cout << (b0|true) << (b0|false) << (b1|true) << (b1|false) << endl; cout << (b0&true) << (b0&false) << (b1&true) << (b1&false) << endl; cout << (b0^true) << (b0^false) << (b1^true) << (b1^false) << endl; cout << (0|b0) << (0|b1) << (1|b0) << (1|b1) << endl; cout << (0&b0) << (0&b1) << (1&b0) << (1&b1) << endl; cout << (0^b0) << (0^b1) << (1^b0) << (1^b1) << endl; cout << ('0'|b0) << ('0'|b1) << ('1'|b0) << ('1'|b1) << endl; cout << ('0'&b0) << ('0'&b1) << ('1'&b0) << ('1'&b1) << endl; cout << ('0'^b0) << ('0'^b1) << ('1'^b0) << ('1'^b1) << endl; cout << (false|b0) << (false|b1) << (true|b0) << (true|b1) << endl; cout << (false&b0) << (false&b1) << (true&b0) << (true&b1) << endl; cout << (false^b0) << (false^b1) << (true^b0) << (true^b1) << endl; cout << b_or(b0,b0) << b_or(b0,b1) << b_or(b1,b0) << b_or(b1,b1) << endl; cout << b_and(b0,b0) << b_and(b0,b1) << b_and(b1,b0) << b_and(b1,b1) << endl; cout << b_xor(b0,b0) << b_xor(b0,b1) << b_xor(b1,b0) << b_xor(b1,b1) << endl; cout << b_or(b0,0) << b_or(b0,1) << b_or(b1,0) << b_or(b1,1) << endl; cout << b_and(b0,0) << b_and(b0,1) << b_and(b1,0) << b_and(b1,1) << endl; cout << b_xor(b0,0) << b_xor(b0,1) << b_xor(b1,0) << b_xor(b1,1) << endl; cout << b_or(b0,'0') << b_or(b0,'1') << b_or(b1,'0') << b_or(b1,'1') << endl; cout << b_and(b0,'0') << b_and(b0,'1') << b_and(b1,'0') << b_and(b1,'1') << endl; cout << b_xor(b0,'0') << b_xor(b0,'1') << b_xor(b1,'0') << b_xor(b1,'1') << endl; cout << b_or(b0,false) << b_or(b0,true) << b_or(b1,false) << b_or(b1,true) << endl; cout << b_and(b0,false) << b_and(b0,true) << b_and(b1,false) << b_and(b1,true) << endl; cout << b_xor(b0,false) << b_xor(b0,true) << b_xor(b1,false) << b_xor(b1,true) << endl; cout << b_or(0,b0) << b_or(0,b1) << b_or(1,b0) << b_or(1,b1) << endl; cout << b_and(0,b0) << b_and(0,b1) << b_and(1,b0) << b_and(1,b1) << endl; cout << b_xor(0,b0) << b_xor(0,b1) << b_xor(1,b0) << b_xor(1,b1) << endl; cout << b_or('0',b0) << b_or('0',b1) << b_or('1',b0) << b_or('1',b1) << endl; cout << b_and('0',b0) << b_and('0',b1) << b_and('1',b0) << b_and('1',b1) << endl; cout << b_xor('0',b0) << b_xor('0',b1) << b_xor('1',b0) << b_xor('1',b1) << endl; cout << b_or(false,b0) << b_or(false,b1) << b_or(true,b0) << b_or(true,b1) << endl; cout << b_and(false,b0) << b_and(false,b1) << b_and(true,b0) << b_and(true,b1) << endl; cout << b_xor(false,b0) << b_xor(false,b1) << b_xor(true,b0) << b_xor(true,b1) << endl; b_or(b, b0, b1); sc_assert(b); b_and(b, b0, b1); sc_assert(!b); b_xor(b, b0, b1); sc_assert(b); }
double _jaro(const char *str1, const char *str2) { // length of the strings, stops the repeated use of strlen int str1_len = strlen(str1); int str2_len = strlen(str2); // if both strings are empty return 1 // if only one of the strings is empty return 0 if (str1_len == 0) return str2_len == 0 ? 1.0 : 0.0; // max distance between two chars to be considered matching // floor() is ommitted due to integer division rules int match_distance = (int) max(str1_len, str2_len)/2 - 1; // arrays of bools that signify if that char in the matcing string has a match int *str1_matches = (int *)calloc(str1_len, sizeof(int)); int *str2_matches = (int *)calloc(str2_len, sizeof(int)); // number of matches and transpositions double matches = 0.0; double transpositions = 0.0; // find the matches for (int i = 0; i < str1_len; i++) { // start and end take into account the match distance int start = max(0, i - match_distance); int end = min(i + match_distance + 1, str2_len); // add comments... for (int k = start; k < end; k++) { // if str2 already has a match continue if (str2_matches[k]) continue; // if str1 and str2 are not if (not_equal(str1[i], str2[k])) continue; // otherwise assume there is a match str1_matches[i] = TRUE; str2_matches[k] = TRUE; matches++; break; } } // if there are no matches return 0 if (matches == 0) { free(str1_matches); free(str2_matches); return 0.0; } // count transpositions int k = 0; for (int i = 0; i < str1_len; i++) { // if there are no matches in str1 continue if (!str1_matches[i]) continue; // while there is no match in str2 increment k while (!str2_matches[k]) k++; // increment transpositions if (not_equal(str1[i], str2[k])) transpositions++; k++; } // divide the number of transpositions by two as per the algorithm specs // this division is valid because the counted transpositions include both // instances of the transposed characters. transpositions /= 2.0; // free dat allocated memory !VERY IMPORTANT! free(str1_matches); free(str2_matches); // return the jaro distance return ((matches / str1_len) + (matches / str2_len) + ((matches - transpositions) / matches)) / 3.0; }
/** * \brief Not equal to operator. */ FRAMEWORK_ALWAYS_INLINE friend bool operator!= (Parent const& lhs, Parent const& rhs) { return not_equal(lhs, rhs); }