astlab at inwind.it astlab at inwind.it
Sun Feb 9 19:00:21 CET 2003

Hi Anton

> To me it seems that your function works properly. I compared the
> results for all cardinal values, using your algorithm
> (cprimes_v.create below) against the results of my own algorithm
> (cprimes_m.create below), which I updated to 32 bits tonight.

I'm happy to read that the function works.

> Shouldn't the function behaviour for n = 0 be discussed? Maybe it's
> worth thinking about returning true or even throwing an exception
> for n = 0?

Also 1 may be an exception. 0 and 1 have no proper factors so maybe
it is more simple to return false for both.

> Did you know that using a series of primes as input to
> 'turtle graphics', where prime modulos determine turtle movement, and
> each turtle move changes pixel colors, leads to very impressive images?

I don't know this, it is interesting and I'll look about it.

> A note on efficiency: On a typical PC, with enough memory but
> performance needs, it might be better to use a one-time created table
> instead of run-time calculation. When the the sieve of Erasthotenes (?)
> is applied with a defined order, there is a relation of similar order
> from a given cardinal number to the number (index) within the set of
> "sieved" numbers.

I agree, the sieve of Erathostenes is very fast so for some applications
may be suitable. But it requires a lot of memory and large arrays.

> In the first lines of assembly, I found a possible optimization, so
> I dared skipping the rest of the assembly text. This optimization would
> be checking > 66 instead of > 61, which speeds up the function for the
> non-prime numbers 62 .. 66.

Good suggestion. 61 is the minimum, because the function must check the
primes up to the bigger base. We can increase the array if there are no
problems of memory or implementation.

> Another note: During inclusion of your sources, I had to convert
> characters of order 160 (0xA0) to spaces - where do those characters
> come from?

Sorry, some tabs of the code end up in the message :). I'll pay more
Thanks for your test.


More information about the fpc-pascal mailing list