real mode dos assembly trouble

All off topic discussions go here. Everything from the funny thing your cat did to your favorite tv shows. Non-programming computer questions are ok too.
User avatar
Zacariaz
Member
Member
Posts: 1069
Joined: Tue May 22, 2007 2:36 pm
Contact:

Post by Zacariaz »

Combuster wrote:You can eliminate a lot of components:
consider all cases where a = b * c (i.e., not prime) and make b >= c
now, the largest value c can attain is b, i.e a = c * c -> c = sqrt(a)

you will only need to check the numbers up to and including sqrt(a) to determine primehood.
I am aware of this, however, as far as i know there is no instruction which calculates sqrt. There is allso other ways of optimizing, but tht is not really the point. This code is just and example of the basic algorithm (or what you call it)

Anyway, i was thinking, that calculation primes in this fasion will result in hitting a limit at some point or another, depentent on how many bits the cpu operates with. Considering this it might be better just to make as sieve, eg. make a list og numer from n 2 to n, then exclude all the the number divisible by 2, 3, 5 etc.

Also, if using the forst methode im considering if it would be a good idea making a list of squares, it qould take up some more memory, but it could drasticly improve the performance...
This was supposed to be a cool signature...
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

Zacariaz wrote:however, as far as i know there is no instruction which calculates sqrt.
FSQRT (all procs), SQRTPS, SQRTPD, SQRTSS, SQRTSD, RSQRTPS (sse), PFRSQRT (3dnow) :wink:
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Post Reply