Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ MT-multithreading and servers » GuiMT example does not calculate all divisors...
GuiMT example does not calculate all divisors... [message #11576] Tue, 18 September 2007 03:03 Go to next message
mr_ped is currently offline  mr_ped
Messages: 825
Registered: November 2005
Location: Czech Republic - Praha
Experienced Contributor
It goes only to sqrt(N) during testing for zero remainders (N mod A == 0).
That is enough to find all divisors, but you need to show not only A, but also B = N/A.

(it's not important in any way to the MT thing, but ... well ... I like when things are exact and accurate)

I would change this:
void WorkerThread(DivisorsInfo f)
{
	String r1, r2;
	int divisors = 0;
	uint64 max = (uint64)sqrt((double)f.number) + 1;
	for(uint64 i = 1; i < max; i++) {
		if(f.gui->terminated)
			break;
		if(f.number % i == 0) {
			r1 << ' ' << i;
			divisors++;
			uint64 j = f.number / i;
			if ( j != i ) {
				r2 = " " + AsString(j) + r2;
				divisors++;
			}
			PostCallback(callback2(f.gui, &Divisors::ShowResult, f.line, "working..." + r1 + r2));
		}
	}
	PostCallback(callback2(f.gui, &Divisors::ShowResult, f.line, AsString(divisors) + ": " + r1 + r2));
	AtomicDec(f.gui->threads);
}
Re: GuiMT example does not calculate all divisors... [message #11589 is a reply to message #11576] Tue, 18 September 2007 17:52 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Indeed. Thanks, patch applied.

Mirek
Previous Topic: typo in manual on web
Next Topic: how to stop a thread that is waiting, e.g., listen()
Goto Forum:
  


Current Time: Fri Mar 29 15:36:44 CET 2024

Total time taken to generate the page: 0.01609 seconds