Algorithm for division. [duplicate] - c++

This question already has answers here:
Algorithm for dividing very large numbers
(5 answers)
Closed 10 years ago.
May be I am already reinventing the wheel.
Normally in C, if we have a=34 and b=5 we get a/b=6. But I need the same thing for 100 digit numbers. I wrote a class with name Int. which does a+b and a-b and a*b. (a,b,c are type Int)
I overloaded the operators << , >>, which will return number divided or multiplied with 10.
What is the best algorithm for division? (assuming I store numbers as strings with base 10".
Thanks.

Perhaps you should consult https://en.wikipedia.org/wiki/Division_%28digital%29, specifically the section on large integer methods.

You're reinventing the wheel. See: http://gmplib.org/

Related

Comparison of data types without using comparisons [duplicate]

This question already has answers here:
Comparing two integers without any comparison
(15 answers)
Closed 5 years ago.
I would like to know how l can overload a function named void maximum to find the maximum of two integer or two double numbers. When passing one integer and one double number function it should print that double vs int or int vs double. And in this case comparisons are not allowed and user should not be asked for input.?
I suggest you subtract one number from another, then check the sign of the result i.e. is it positive, negative or zero, and based on this determine which was larger.

Typecasting processed float value to int reduces the actual value [duplicate]

This question already has answers here:
Floating point arithmetic not producing exact results [duplicate]
(7 answers)
Closed 8 years ago.
In C++, floor(9099.96 *100.0) is giving me the answer as 909995. I am expecting 909996.
I am not able to think of explanations here. Any help will be appreciated.Thanks.
This is the proper result: according to IEEE754 calculator, the value of 9099.96 is represented as 9099.9599609375 in double. After multiplication by 100 you get 909995.99609375. Taking floor gives you 909995.
Try ceil. It will always round the the next greatest number, which in this case will give you 909996. You may also want to look at the round function.

Handling large integers in c++ [duplicate]

This question already has answers here:
Using extremely large integer holding 3001 digits
(2 answers)
Closed 9 years ago.
How can i handle very large integers like 2^100000000 in c++?
I found no solution for this on internet that gives an exact answer.
Is there any mechanism that gives correct value in c++ for such large integers?
What you are looking for is called arbitrary precision arithmetic, you will find numerous libraries and educational resources with some googling.
You can represent given number as a string and convert it to array with integer digits. But the simplest way to google by keywords "long arithmetic c++ library" or something.
Maybe you want to use a Computer Algebra System (CAS), which would represent your expression like this:
class Pow : public Expr {
Number base;
Number exp;
};
Pow expr = new Pow(2, 100*1000*1000);
A CAS then allows you to manipulate these expressions structurally instead of the concrete values.

Dividing the integers in two separate arrays [duplicate]

This question already has answers here:
Array Division - What is the best way to divide two numbers stored in an array?
(7 answers)
Closed 9 years ago.
What I am trying to do is when given two arrays:
{1,5,1,7},
{4,1}
I want to get {3,7}. BTW, 1517 / 41 = 37
I can't think of simple algorithm to accomplish this. I can't simply convert the arrays into integers and use the regular division operator, because numbers in the arrays could be very huge that integers can't hold.
I've heard that using long division can help, but when I read it on Wikipedia, it only explains how to do math (http://en.wikipedia.org/wiki/Long_division). I know how to divide two numbers.
If you were to write some code, I'd prefer c++, but doesn't matter.
Any help will be appreciated.
If you use Python, this is easy.
f = lambda L: int(''.join(map(str,L)))
a = [1,5,1,7]
b = [4,1]
print map(int,str(f(a) / f(b))) # [3, 7]

Fortran technical query [duplicate]

This question already has an answer here:
What is meant by . usage after a number in Fortran?
(1 answer)
Closed 3 years ago.
I have the following function signature in Fortran. I am new to the Fortran language - what is meant by 0. in the function below?
ANTY(IAN,NA,0.,0.)
The notation 0. with a decimal point represents a floating point number, while 0 without a decimal point represents an integer. This is an important distinction for some implementations of FORTRAN, where the programmer must ensure that data types are consistent between the caller of a subroutine and the subroutine itself.
It is equivalent to 0.0 as a 32 bit real number (float in C)