Alex Shinn scripsit: > #;1> (arithmetic-shift 1 31) > 2147483648.0 > #;2> (arithmetic-shift 1 32) > 1 > #;3> (* 2 (arithmetic-shift 1 31)) > 4294967296.0
This inconsistency is a consequence of Chicken's default fixnum-flonum architecture. Arithmetic-shift verifies that its arguments are integral and will fit in a full word (32 or 64 bits as the case may be), and then uses the C << and >> operators to do a full-word shift. However, the second argument is effectively reduced modulo the width of a full word, at least on x86-family processors. The C standard permits this behavior; it is undefined what happens when you shift a negative number or to shift all the bits away. In any case, if the result is too big to fit in a fixnum, Chicken converts it to a flonum instead. As with most numeric problems, the cure is to do (use numbers) first. -- John Cowan http://ccil.org/~cowan [EMAIL PROTECTED] There are books that are at once excellent and boring. Those that at once leap to the mind are Thoreau's Walden, Emerson's Essays, George Eliot's Adam Bede, and Landor's Dialogues. --Somerset Maugham _______________________________________________ Chicken-users mailing list [email protected] http://lists.nongnu.org/mailman/listinfo/chicken-users
