Comments (6)
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.
If you feel like it then sure, go ahead. I'd appreciate it.
from bigint.
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.
Sounds good. But make it a private method. I want to keep the public api simple.
from bigint.
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.
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)
- Error in VS2013 debug enviroment when call "pow" functin HOT 1
- Dead code found at line 78 HOT 3
- Some question about division operation HOT 2
- subtraction considered fail HOT 7
- Bug with big number multiplication HOT 1
- Test coverage HOT 4
- Failed cases HOT 1
- operator* and operator*= HOT 2
- Power of zero HOT 2
- how to (XOR, OR, AND...)? HOT 1
- Incorrect product sign for negative values
- Why doesn't this class support division and modulus? HOT 1
- Performance issue in Bigint::pow function
- if(n==0){//do not work
- use bigint with a class
- Not correct string number HOT 3
- Is there a way to get an unsigned version of bigint? HOT 1
- Incorrect initialization with numeric zero
- comparison with 0 cause error HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bigint.