GithubHelp home page GithubHelp logo

Comments (2)

posidoni avatar posidoni commented on August 21, 2024 1

This causes stack overflow. Probably this is also due to incorrect comparison of negative numbers. Andrey was writing & testing his functions with old buggy Stepan's comparisons. Probably we need to write ADD, SUB, MUL, DIV from scratch 🍭 This is not that hard actually. We brainstormed this with Stepa this evening.

Moreover, we will write our own functions & rewrite completely unreadable Andrey's code.

START_TEST(int64_t_negatives) {
    int64_t long_a = get_random_ll();
    int64_t long_b = get_random_ll();

    if (rand() % 2)
        long_a *= -1;

    if (rand() % 2)
        long_b *= -1;

    int64_t a = long_a;
    int64_t b = long_b;

    int64_t sum = a + b;

    s21_decimal res128 = {0};

    for (long long int i = 0, k = 0; i < 2; i++)
        for (long long int j = 0; j < 32; j++, k++)
            if (IS_SET(sum, k))
                ADD_BIT(res128.bits[i], j);

    s21_decimal dec_a = ll_to_decimal(long_a);
    s21_decimal dec_b = ll_to_decimal(long_b);
    s21_decimal dec_sum = {0};

    s21_add(dec_a, dec_b, &dec_sum);
    /* print_bits_r(dec_sum); */

    ck_assert_int_eq(s21_is_equal(res128, dec_sum), TRUE);
}

Suite *suite_s21_add(void) {
    Suite *s = suite_create(PRETTY_PRINT("s21_add"));
    TCase *tc = tcase_create("s21_add_tc");

    /* tcase_add_loop_test(tc, add_test1, 0, 1); */
    tcase_add_loop_test(tc, gcc_128_bits, 0, 10000);
    tcase_add_loop_test(tc, int64_t_negatives, 0, 10000);

    suite_add_tcase(s, tc);
    return s;
}

image

from s21_bigint.

posidoni avatar posidoni commented on August 21, 2024

It turns out there were two bugs with s21_sub. Now everything works fine. #57 closes this issue.

from s21_bigint.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.