GithubHelp home page GithubHelp logo

Comments (6)

SethPoulsen avatar SethPoulsen commented on May 28, 2024

I've never contributed to a project on GitHub before, so I'm not sure how to do the "pull request" thing, but adding this to the .cpp (with a corresponding declaration in the .h) does the trick to give the modulo if you want to do Bigint % int:

//Modulo
int Bigint::operator%(int divisor)
{
    long int remains = 0;
    for (int i = 0; i < number.size(); i++){
        remains = (remains + number[number.size() - i - 1]) % divisor;
        if(i != number.size() - 1)
        {
            remains = remains*base;
            remains %= divisor;
        }
    }
    if(positive)
        return remains;
    else
        return -remains + divisor;
}

I'm going to get to work now on figuring out how to implement Bigint % Bigint

Sorry my formatting is bad, I'd appreciate any tips on how to use the site better and how to properly request that this be put into the code.

from bigint.

kasparsklavins avatar kasparsklavins commented on May 28, 2024

If you feel like it then sure, go ahead. I'd appreciate it.

from bigint.

SethPoulsen avatar SethPoulsen commented on May 28, 2024

I'm realizing, if I'm going to do Bigint % Bigint, then I might as well do Bigint / Bigint , because you basically have to do the division to get the remainder. I would think we would want both functions to use essentially the same code.

Should we have an option to return just the quotient, just the remainder, and an option to return both the quotient and the remainder?

from bigint.

kasparsklavins avatar kasparsklavins commented on May 28, 2024

Sounds good. But make it a private method. I want to keep the public api simple.

from bigint.

SethPoulsen avatar SethPoulsen commented on May 28, 2024

Ok, that sounds good. I'll need to use the multiplication and subtraction to do it (well, it will make it a lot easier). Are those stable right now?

from bigint.

kasparsklavins avatar kasparsklavins commented on May 28, 2024

Multiplication seems produce incorrect results in some cases, I'll go over it later today (or tomorrow, depending on the timezone)

from bigint.

Related Issues (20)

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.