Opstad.osbunorth@Xerox.COM (08/24/86)
I discovered this little problem while writing a prime factorization program. Consider the following fragment: unsigned long i; i = 16777216L; printf("%ld\n", i); i /= 2; printf("%ld\n", i); Imagine my surprise when the same number is printed by both printf calls! When I changed the fourth line to: i >>= 1; the program worked fine and printed the correct results. Has anyone else had problems with division using Lattice/Metacomco C? (I'm using version 3.03.04) Dave Opstad (Opstad.osbunorth@Xerox.COM)
gert@nikhefh.uucp (Gert Poletiek) (08/26/86)
In article <860824-115320-1121@Xerox> Opstad.osbunorth@Xerox.COM writes: > > I discovered this little problem while writing a prime factorization >program. Consider the following fragment: > > unsigned long i; > i = 16777216L; > printf("%ld\n", i); > i /= 2; > printf("%ld\n", i); > > Imagine my surprise when the same number is printed by both printf >calls! When I changed the fourth line to: > > i >>= 1; > > the program worked fine and printed the correct results. Has anyone >else had problems with division using Lattice/Metacomco C? (I'm using >version 3.03.04) > > Dave Opstad (Opstad.osbunorth@Xerox.COM) How about it ? This bug was mentioned on the distribution leaflet as a KNOW BUG in Lattice 3.03.04. If memory serves me right all factor of two divisions are converted to a shift, but the shift count is one too small; ie. /2 becomes >>0 and /4 becomes >>1 Nice Uh ? Gert Poletiek Dutch Nation Institute for High Energy Physics Amsterdam The Netherlands
jhs@MITRE-BEDFORD.ARPA (08/29/86)
Anyone who tries to write a prime factorization program is silly because primes have only the trivial factors 1 and p where p is the prime in question. (!) -John Sangster jhs@mitre-bedford.arpa