Ejemplo n.º 1
0
char	*my_modulo(char *n1, char *n2)
{
    t_div *d;

    d = init_my_mod(n1, n2);
    if ((d != NULL) && (my_str_isnum(d->dvd) == 1) && (my_str_isnum(d->dvs) == 1))
        if (d->dvs[0] != '0')
        {
            while (d->dvd[0] != '-')
            {
                if ((my_do_op_sub_cmp(d->dvs, d->dvd, 0, 0) == 0) &&
                        (d->mod[0] == '0'))
                    my_strcpy(d->mod, d->dvd);
                my_strcpy(d->temp_cmp, d->dvs);
                my_strcpy(d->temp_fact, "1");
                while (my_do_op_sub_cmp(d->temp_cmp, d->dvd, 0, 0) == 1)
                    add_zero(d);
                (check_digits(d) == 1) ? (add_zero(d)) : (1);
                remove_zero(d);
                if (check_digits(d) == 1)
                    d->temp_fact = add_sub(d->temp_fact, "-1");
                get_minus(d->temp_cmp);
                d->total = add_sub(d->total, d->temp_fact);
                d->dvd = add_sub(d->dvd, d->temp_cmp);
            }
            free(d);
            return (check_neg(d, d->mod, 2, 0));
        }
        else
            my_putstr(DIV_0);
    return (0);
}
Ejemplo n.º 2
0
BigInt::reference BigInt::normalize()
{
    // leading 0
    remove_zero(buffer);

    // +-0
    if ( buffer.size() == 1 && buffer[0] == 0 )
        sign_ = false;

    return *this;
}
Ejemplo n.º 3
0
BigInteger& BigInteger::operator*(BigInteger &other_obj){
    char one[2] = "1";
    BigInteger integer_1(one);
    BigInteger *integer_multi = NULL;

    unsigned long len = (*other_obj.get_data_string()).length();
    for (int i = 0;  i < len; i++) {
        int count = convert_char_to_int((*other_obj.get_data_string())[i]);
        BigInteger *integer_plus = NULL;
        BigInteger *integer_plus_pointer = NULL;
        BigInteger *integer_multi_pointer = NULL;
        if (count == 0){
            char zero[2] = "0";
            integer_plus = new BigInteger(zero);
        }else{
            while (count--) {
                if (integer_plus == NULL) {
                    string *plus_str = (this->get_data_string());
                    integer_plus = new BigInteger(*plus_str);
                    integer_plus_pointer = integer_plus;
                }else{
                    integer_plus = &((*this)+(*integer_plus));
                    delete integer_plus_pointer;
                    integer_plus_pointer = integer_plus;
                }
            }
            string_append_zero(integer_plus->data_string, (int)(len-i-1));
        }
        if (integer_multi == NULL) {
            string *plus_str = (integer_plus->get_data_string());
            integer_multi = new BigInteger(*plus_str);
            integer_multi_pointer = integer_multi;
        }else{
            integer_multi = &(*(integer_plus) + *(integer_multi));
            if (integer_multi_pointer != NULL) {
                delete integer_multi_pointer;
            }
            integer_multi_pointer = integer_multi;
        }
//        delete integer_plus_pointer;
//        delete integer_multi_pointer;
    }
    remove_zero(*integer_multi);
    BigInteger *result = new BigInteger(*(*integer_multi).get_data_string());
    return *result;
}