Integer overflow. user> (mod 9876543210 (bigint (Math/pow 2 32))) 1286608618
On Sep 11, 9:44 pm, George Kangas <gwkan...@gmail.com> wrote: > I believe the bug can be blamed on "nth". > > Using "nth", I make a function which should be identity on natural > numbers: > > Clojure 1.2.1 > user=> (defn ident [n] (nth (iterate inc 0) n)) > #'user/ident > > And it works, for reasonable size numbers: > > user=> (ident 12345) > 12345 > user=> (ident 7654321) > 7654321 > > But, with a ridiculously huge number... > > user=> (ident 9876543210) > 1286608618 > > ...something goes wrong. > > Also, when I replace "nth" in my code (in the top post) with "mth", > then it works. Here's "mth": > > user=> (defn mth [seq m] (if (zero? m) (first seq) (recur (rest seq) > (dec m)))) > #'user/mth > user=> (mth (iterate inc 0) 123456) > 123456 > user=> (mth (iterate inc 0) 9876543210) > 9876543210 > > Of course, "mth" is godawful slow. > > I guess nobody wanted to find the 9876543210th element of a sequence, > until this wanking dilettante came along! > > cheers, > George -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en