It was thus said that the Great Jerome H. Fine once stated:
I suspect that there is gross confusion over pi (to how many figures of
accuracy you choose) and PI(N) which is the NUMBER of primes
between 2 and the number N. NOTE that in both cases, the GREEK
letter "pi" is used (I do not know how to type GREEK letters under
Netscape!!). Why the GREEK letter "pi" is used for PI(N) is beyond
my comprehension, but if you google "prime numbers" and look at a
few of the references, you will find it there. For example:
N PI(N)
10 4 (the primes are 2, 3, 7, 9)
100 25
1,000 168
10,000 1,229
100,000 9,592
By the way, I just learned this use for "pi" this year even though I
have been curious about prime numbers for over 20 years. I finally
requested some books from the library and then did a few googles.
Oh. I didn't know that either!
Easy enough
method---just multiply the absolute values and record the
signs prior to multiplication, then reset the sign afterwards to the correct
value.
That is too easy a solution - anything a bit more difficult?
You could do it 8-bits at at time. Something like (using VAX assembly, as
that's probably close enough to PDP-11):
;assuming A[0] = MSW, and that each "number"
;is 7 bytes long
;r0 - src 1
;r1 - src 2
;r2 - dest
;r3 - count
;r4 - src1[count]
;r5 - src2[count]
;r6 - prev carryover
movw #7,r3
clrw r6 ; clear carry over
.loop: clrw r4 ; clear tmp registers
clrw r5
movb (r0)[r3],r4 ; get unsigned byte into signed word
movb (r1)[r3],r5
mulw r4,r5 ; do signed multiplication
addw r6,r5 ; add in previous "carry over"
movb r5,(r2)[r3] ; save result
rotl -8,r5,r6 ; save "carry over"
bitcw #00FF,r6 ; make sure "carry over" is between 0 - 255
sobgeq r3,.loop ; loop
Get's around the fact that the MUL instruction is signed only, even though
the longer number is unsigned.
More seriously, if I am using all 16 bits as unsigned
integers, then
the high order bit can't be easily eliminated. Of course another
method is to keep all the values below 10,000 decimal which
can then allow me to use FORTRAN much more easily. But
I really prefer to use the full 64 bits. On the other hand, if I
use the sieve method to find the primes, I don't need either
multiplication or division, just 64 bit adding and 64 bit compares,
probably increments by 2 and 4 and of course conversion of
64 bit values to decimal output. The last can also be done by
repeated subtraction of powers of 10, so again no division.
If you do have a DIV instruction, and for printing out the result, it's
easy to divide through the large number by 10 (as long as you get both the
quotient and remainder from the DIV instruction). I have some 8086 code to
print 32-bit quanities (given that the 8086 only supports a 16-bit DIV
operation).
-spc (Always did love the VAX assembly language ... )