Visual Basic 2010 General DiscussionFor any discussions about Visual Basic 2010 topics which aren't related to a specific Wrox book
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Visual Basic 2010 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
But you know, he gives you the C++ code for it. There's no reason you can't use Visual C++, compile that code into a library, and then invoke that library function from VB.
EDIT: No, I take that back. He said he uses a #define to set the number of places of accuracy, so you'd have to change even his code if you wanted to convert it into a callable library with arbitrary precision.
Last edited by Old Pedant; October 27th, 2010 at 07:46 PM.
The Following User Says Thank You to Old Pedant For This Useful Post:
I hope you noted that he said it took 15 hours on his PC to get 1,000,000 places.
Aye, but that's really not much when you consider the vast amount of calculations involved. I only really wanted to find enough to fill the first 25 lines of the console window, even with the algorithm I was using that should take only a matter of seconds... I think I shall abandon this project and leave it for when I have a better understanding of programming.
In the mean time I think I may make another Prime Generator, this time using the Sieve of Atkin. That should be quite simple right?
PS: If I want to create a .txt file to save the prime numbers in what would be the best way of going about this?
__________________ "Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction." - Albert Einstein
Used to use Sieve of Erastothenes as a benchmarking program. Can't tell you how many languages I wrote that in. But in those days (1970s, early 80s), we were happy to get the primes up to about 16,000.
The Following User Says Thank You to Old Pedant For This Useful Post:
Cool, I use Prime95 for stability testing overclocks all the time, I guess it must be generating some pretty huge primes!
Do you think Sieve of Eratosthenes would be a better option then? It is simpler to implement.
__________________ "Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction." - Albert Einstein
The big limitation back in the day was the amount of memory needed. You need an array element for each number from 1 to N. (Well, we "cheated" by only looking at odd numbers, so we needed half that number of elements, but you get the idea.)
In the BASICs of that day, where many implemented only a single numeric data type which was, of course, floating point, that meant the you were using 4 or 6 or 8 bytes per array element. In a 64KB machine, you usually only had a MAX of 32KB left for variables, so even 32K divided by 4 meant a top end of 8000 array elements.
In a modern machine, you can surely devout a few hundred megabytes to the array *AND* with VB.NET (for example) your array elements can each be only 1 byte long (that is, use an array of BYTE data type). So sure...it's thus trivial to implement and you can get up into the range of 1,000,000,000 as a max prime (esp. if you pull the same trick: Don't use an array element for the even numbers).
Actually, VB.NET is fast enough that if you wanted to get a bit more clever you could extend the range by a factor of 8 by using only 1 BIT per odd number. A little more coding work, but not hard.
The Following User Says Thank You to Old Pedant For This Useful Post:
Could you modify my code so that it will display 28 decimal places of π please? That would be awesome.
Also how would I write a routine which sorts an array of strings into alphabetical order? It's really bugging me!
__________________ "Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction." - Albert Einstein
Could you modify my code so that it will display 28 decimal places of π please? That would be awesome.
Tell the truth, I've never used DECIMAL with VB before. But I would imagine all you have to do is change all the variables to DECIMAL. Oh, and get rid of Math.Pow(). Just have to do that "by hand" with multiplies, instead.
Quote:
Also how would I write a routine which sorts an array of strings into alphabetical order? It's really bugging me!
I was aware of that function, I wanted to write the routine myself because my tutor had challenged me to do so over half-term. I could get it to work easily for numerical values, but it didn't work for Strings...
__________________ "Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction." - Albert Einstein