I can confirm weird behavior (and I get different weird results): Welcome to Racket v6.5. > (define num #xffffffffffffffff) (for ([i 5]) (printf "~a~n" (bitwise-ior (bitwise-and num -2) 0))) 2192618128 2192618180 2192618200 2192618668 2192618688 > (for ([i 5]) (printf "~a~n" (bitwise-ior (bitwise-and num -2) 0))) 2192791964 2192792016 2192792036 2192792504 2192792524 > (bitwise-and num -2) 18446744073709551614 > (bitwise-and num -2) 18446744073709551614 > (bitwise-and num -2) 18446744073709551614 > (bitwise-and num -2) 18446744073709551614 > (define h (bitwise-and num -2)) > (for ([i 5]) (printf "~a~n" (bitwise-ior h 0))) 18446744073709551614 18446744073709551614 18446744073709551614 18446744073709551614 18446744073709551614 > (for ([i 5]) (printf "~a~n" (bitwise-ior h 0))) 18446744073709551614 18446744073709551614 18446744073709551614 18446744073709551614 18446744073709551614
--John Boyle *Science is what we understand well enough to explain to a computer. Art is everything else we do.* --Knuth On Thu, Oct 13, 2016 at 9:17 AM, <peter.sama...@gmail.com> wrote: > Hi all, > > I get a weird behavior when using bitwise-ior and bitwise-and with large > numbers. Tested on 2 machines (racket 6.6, Ubuntu 16.04 and 14.04): > > Here is the test example: > > #lang racket > (define num #xffffffffffffffff) ;; remove one f, and the results are fine > in both cases > (for ([i 5]) > (printf "~a~n" (bitwise-ior (bitwise-and num -2) 0))) > > > When run from DrRacket using ctr+r, it works properly: > 18446744073709551614 > 18446744073709551614 > 18446744073709551614 > 18446744073709551614 > 18446744073709551614 > > When pasted into DrRacket's REPL (or run from command line via "racket > random-bug.rkt"), the code does not only produce wrong result, but also > seems to be counting something :) > 70112357026588 > 70112357038692 > 70112357043588 > 70112357048576 > 70112357053344 > > Removing one "f" from the test number results in correct behavior in both > cases. > Very large numbers are are reduced to the same range (around 54 bits). > Replacing the expression (bitwise-and num -2) by the corresponding number > it computes results in correct behavior. > > Cheers, > Peter > > -- > You received this message because you are subscribed to the Google Groups > "Racket Developers" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to racket-dev+unsubscr...@googlegroups.com. > To post to this group, send email to racket-dev@googlegroups.com. > To view this discussion on the web visit https://groups.google.com/d/ > msgid/racket-dev/d0310d90-0d88-4902-b430-0069b310d7a3%40googlegroups.com > <https://groups.google.com/d/msgid/racket-dev/d0310d90-0d88-4902-b430-0069b310d7a3%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Racket Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-dev+unsubscr...@googlegroups.com. To post to this group, send email to racket-dev@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/racket-dev/CABzzEgnaQ32wc_yVs38K1m356PQmg6uEp71thJp4KHQvEOzC7w%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.