Re: is it a bug in clojure? unchecked-multiply
Note that using the auto-promoting ops will automatically overflow into an arbitrary precision type: user=> (*' 3037000500 3037000500) 922337203700025N user=> (*' 1000 1000) 100N The trailing N indicates the arbitrary precision integer. On Friday, March 3, 2017 at 10:56:43 AM UTC-6, redc...@gmail.com wrote: > > On 03/03/2017 12:14 AM, BongHyeon. Jo wrote: > > (unchecked-multiply 1000 1000) > > The default type clojure uses for integers is the jvm's long (or the > boxed variant Long) type. Longs are signed 64bit numbers. > 100 is outside the range of longs. > `(* 1000 1000)` will throw an error because of the > overflow. `(*' 1000 1000)` will promote the result to a > BigInt (most ops have a primed variant that auto promotes). The > `unchecked` in `unchecked-multiply` means it doesn't check the result, > so overflow silently happens, as you have seen. The `unchecked` variants > are intended for use when you are sure overflow is ok and you want the > fastest possible math. > > -- > And what is good, Phaedrus, > And what is not good— > Need we ask anyone to tell us these things? > -- 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 --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: is it a bug in clojure? unchecked-multiply
On 03/03/2017 12:14 AM, BongHyeon. Jo wrote: > (unchecked-multiply 1000 1000) The default type clojure uses for integers is the jvm's long (or the boxed variant Long) type. Longs are signed 64bit numbers. 100 is outside the range of longs. `(* 1000 1000)` will throw an error because of the overflow. `(*' 1000 1000)` will promote the result to a BigInt (most ops have a primed variant that auto promotes). The `unchecked` in `unchecked-multiply` means it doesn't check the result, so overflow silently happens, as you have seen. The `unchecked` variants are intended for use when you are sure overflow is ok and you want the fastest possible math. -- And what is good, Phaedrus, And what is not good— Need we ask anyone to tell us these things? -- 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 --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
is it a bug in clojure? unchecked-multiply
3037000500 * 3037000500 = 922337203700025 1000 * 1000 = 100 ( 10^11 * 10^11 = 10^22) but , in clojure user=> (unchecked-multiply 3037000500 3037000500) -9223372036709301616 user=> (unchecked-multiply 1000 1000) 1864712049423024128 is it a bug in clojure? -- 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 --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.