andyd273
asked on
Mod dividing very large numbers
I am working on a program that has to divide a very large number by a prime and make sure it divided cleanly (no remainder)
Do While dblLtrNum Mod conPrime(dblPrm) = 0
where dblLtrNum = 4.05827141822066E+178 or some other large number and conPrime(dblPrm) = 2 or some other prime.
processing time isnt much of a consideration
I'm really not sure if VB can actually handle what I want it to do, and if there is another language that would work better with super huge numbers I'm open to suggestions.
Do While dblLtrNum Mod conPrime(dblPrm) = 0
where dblLtrNum = 4.05827141822066E+178 or some other large number and conPrime(dblPrm) = 2 or some other prime.
processing time isnt much of a consideration
I'm really not sure if VB can actually handle what I want it to do, and if there is another language that would work better with super huge numbers I'm open to suggestions.
You will not be able to use Double data type supported by VB in order to do this.
Double data type can handle numbers up to 1.79769313486232E+308 but with an accurancy of 15 digits. You will be able to divide big numbers but you will not be able to make sure if they are divied with a remainder or not.
Consider the numbers:
12345678901234567890
and
12345678901234567891
in Double data type they are both stored as :
1.23456789012346E+19
so there is no distinction between them.
In order to do this you will need to create your own data type, a data type that can handle 200-300 digits. One way to do this is to store those digits in an array of integers. You could also store those numbers in strings.
In any case you will need to write your own routines for division.
Double data type can handle numbers up to 1.79769313486232E+308 but with an accurancy of 15 digits. You will be able to divide big numbers but you will not be able to make sure if they are divied with a remainder or not.
Consider the numbers:
12345678901234567890
and
12345678901234567891
in Double data type they are both stored as :
1.23456789012346E+19
so there is no distinction between them.
In order to do this you will need to create your own data type, a data type that can handle 200-300 digits. One way to do this is to store those digits in an array of integers. You could also store those numbers in strings.
In any case you will need to write your own routines for division.
You might consider having a look at powerbasic (www.powerbasic.com). This supports an extended precision data type with range
+/- 4.19E-4931 to +/- 1.2E+4932
With powerbasic you can generate a straight Win32 DLL which you can then plug into the rest of your application.
+/- 4.19E-4931 to +/- 1.2E+4932
With powerbasic you can generate a straight Win32 DLL which you can then plug into the rest of your application.
Or you can simply convert the number to a string and do the division the way you would by hand--slow and tedious, but guaranteed to work (if you have enough memory to hold the strings and temp strings.) Just be warned that this will be VERRRRYYYY slow.
ASKER
Hmm, IC
I guess I never realized that VB's scientific notation only went 15 places... that could be a bigger problem then cause my program also has to generate the numbers based on user imput. is there anyway to force it not to use scientific notation when multiplying something like 20^15? if possible it could actually help solve a few problems.
I guess I never realized that VB's scientific notation only went 15 places... that could be a bigger problem then cause my program also has to generate the numbers based on user imput. is there anyway to force it not to use scientific notation when multiplying something like 20^15? if possible it could actually help solve a few problems.
I think you can use the Format$ function, but it won't necessarily give you any more precision, so the resulting number may be wrong (at the least significant digits)!
rspahitz is right. you won't get any more precision. Even the extended data type I mentioned above will only give you 18 significant figures.
The real answer here is going to be to generate your own data type, and write your own functions to do the multiplication and division using bit shifting. This is the way that processors manage multiplication and division. That way you can implement a custom data type with as much precision and as large a size as you want.
There is some more info on this, and some more information on a "Greatest Common Factor Calculator" in the link below.
http://www.owlnet.rice.edu/~cavallar/elec422/2000/proj/f00/M_GCF_Gen.pdf
It's not an easy answer, but then much of modern cryptography is based on the premise that there is no easy way to factorise large primes.
The real answer here is going to be to generate your own data type, and write your own functions to do the multiplication and division using bit shifting. This is the way that processors manage multiplication and division. That way you can implement a custom data type with as much precision and as large a size as you want.
There is some more info on this, and some more information on a "Greatest Common Factor Calculator" in the link below.
http://www.owlnet.rice.edu/~cavallar/elec422/2000/proj/f00/M_GCF_Gen.pdf
It's not an easy answer, but then much of modern cryptography is based on the premise that there is no easy way to factorise large primes.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi andyd273,
It appears that you have forgotten to close this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:
Accept molar's comment(s) as an answer.
*** points for originality!
andyd273, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you. DO NOT accept THIS comment as an answer.
EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
It appears that you have forgotten to close this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:
Accept molar's comment(s) as an answer.
*** points for originality!
andyd273, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you. DO NOT accept THIS comment as an answer.
EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
If (dblLtrNum / conPrime(dblPrm) = int((dblLtrNum / conPrime(dblPrm)) or something like that