Hi i need to multiply two numeric string value i already created one but its not fast enough . I use same method when we doing in paper first i multiply all characters and saved in a vector and then later added all multiplyed output using string add function that i created . can't post that code becuse its big and not readable
I need a better multiply function how can i create one
And what is arbitrary precision i goto this website its good is this method faster than others
That depends on your platform, compiler toolchain, and the library itself. It can be as simple as including a header file, though often it requires a little more, e.g., compiling one or more source files and/or linking to a library file.
Originally Posted by Ramees219
and if included GMP how i use to multiply two strings ???
Read the documentation provided at the website that I linked to. You will not be multiplying two strings; you would be multiplying two numbers.
C + C++ Compiler: MinGW port of GCC
Build + Version Control System: SCons + Bazaar
'Big Integer' arithmetic is not usually done using a string to store the digits, as this method is slow - as you're found! If you have need for 'big integer' arithmetic then as laserlight suggested you should be looking at using an existing available library.
Last edited by 2kaud; January 1st, 2016 at 05:54 AM.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
The usual way is to convert the strings to a C++ fundamental type and then perform calculations on that type.
For example if you use long long int you can handle integers in the -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 range.
If you instead use a double you get roughly the same precision but an even wider range ± 1.797,693,134,862,315,7 · 10^308.
If that's not enough I suggest you try to scale your problem before resorting to an arbitrary precision package. How much precision do you need really?
Maybe 7000 digit precision . If i am use any other arbitrary precision library how much time its going to take to multiply 7000 digit * 7000
On a single core i just want know a minimum time
And i just found that Schönhage-Strassen algorithm can multiplying very large integers in a reasonable amount of time.and also found code in this site but it's not running in my visual studio 2013 errors..... http://googleweblight.com/?lite_url=...jg93mZgc79arYA
Last edited by Ramees219; January 2nd, 2016 at 01:19 PM.
The reason that the program doesn't compile with VS2013 is that it is trying to define the size of the array linearConvolution at runtime which is not allowed.
replace
Code:
int linearConvolution[n + m - 1];
for (int i = 0; i < (n + m - 1); i++)
linearConvolution[i] = 0;
with
Code:
vector<int> linearConvolution(n + m - 1, 0);
and at the top of the program insert
Code:
#include <vector>
Note that this code only works for some input values. The given example produces the correct answer, but 34 * 56 doesn't - produces 904 instead of 1904; 5 * 7 produces 5. eg it sometimes leaves off the most significant digit in the answer. You'll need to debug the code to find the problem.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
hi
i think fond a way to fix this problem . i don't know it already exists or not . i think its give 2000 digit value multiplication run fast
but i can't code this my own i am confused pls help me
my English is low i tried my best explain multiplication.jpg
Last edited by Ramees219; January 16th, 2016 at 01:07 AM.
Um, that looks like the beginning of an approach leading to the Karatsuba multiplication algorithm.
I suggest that you go back to trying to get a third party library to work for you, and see if it meets your needs. Implementing this yourself would be a good exercise, but if you are going to give up so easily with "but i can't code this my own i am confused pls help me", then there's no point.
C + C++ Compiler: MinGW port of GCC
Build + Version Control System: SCons + Bazaar
i don't like to use library because i can't full understand it i need to do this way with maximum optimized for my problems
i am not give up on this i am full confided to code this but i am not sure it going to run maximum optimized i need an example by using
an a dynamic array .
my confusions
1, how to optimize this code to maximum speed
2, how to using dynamic array in this
3, how to get a range of 9 digit 9 digit value form dynamic array input to perform multiplication
i don't like to use library because i can't full understand it i need to do this way with maximum optimized for my problems
If you cannot understand a library with available code that was written for your scenario and that was optimised by people who have been researching and experimenting with this much longer than you, then you have no hope at all of writing your own code such that it is "maximum optimized" for your problems.
Originally Posted by Ramees219
1, how to optimize this code to maximum speed
You don't even have any code to speak of. You have an algorithm, but are you sure it is the most efficient algorithm? In the end, you may have to investigate and implement multiple algorithms to see which one is most efficient for your typical input.
Originally Posted by Ramees219
2, how to using dynamic array in this
If you have to ask this: use a library.
Originally Posted by Ramees219
3, how to get a range of 9 digit 9 digit value form dynamic array input to perform multiplication
If you have to ask this: use a library.
C + C++ Compiler: MinGW port of GCC
Build + Version Control System: SCons + Bazaar
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.