This is the mail archive of the guile@sourceware.cygnus.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: logxxx and bignums



                                Hello,
I hope everyone agrees that bit operations should treat negative
integers (bignums and fixnums) as two's complements (like CL does)
even if they might be implemented differently?

[this is from CVS as of June last year, before they installed a
  firewall here :-( ]

guile> (map (lambda (pos) (list pos (logbit? pos -1))) (iota 40))
((0 #t) (1 #t) (2 #t) (3 #t) (4 #t) (5 #t) (6 #t) (7 #t) (8 #t) (9 #t)
 (10 #t) (11 #t) (12 #t) (13 #t) (14 #t) (15 #t) (16 #t) (17 #t) (18 #t) 
 (19 #t) (20 #t) (21 #t) (22 #t) (23 #t) (24 #t) (25 #t) (26 #t) (27 #t)
 (28 #t) (29 #t) (30 #f) (31 #f) (32 #t) (33 #t) (34 #t) (35 #t) (36 #t)
 (37 #t) (38 #t) (39 #t))

So -1 is a 30-bit two's complement number.

SCM version 4e6 (yes, I know it's old, but it does handle bignums)
gets this right:

> (map (lambda (pos) (list pos (logbit? pos -1))) (iota 40)
((0 #t) (1 #t) (2 #t) (3 #t) (4 #t) (5 #t) (6 #t) (7 #t) (8 #t) (9 #t) 
 (10 #t) (11 #t) (12 #t) (13 #t) (14 #t) (15 #t) (16 #t) (17 #t) (18 #t)
 (19 #t) (20 #t) (21 #t) (22 #t) (23 #t) (24 #t) (25 #t) (26 #t) (27 #t)
 (28 #t) (29 #t) (30 #t) (31 #t) (32 #t) (33 #t) (34 #t) (35 #t) (36 #t)
 (37 #t) (38 #t) (39 #t))

> (map (lambda (pos) (list pos (logbit? pos (* -1 (expt 2 100))))) 
       '(98 99 100 101 102))
((98 #f) (99 #f) (100 #t) (101 #t) (102 #t))

                                      HTH
                                        Roland

P.S. I'm glad to hear Mikael is back!

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]