I've always thought this is bad behavior, since it's blatantly doing the 
opposite of what the name advertises. I think either the boxed versions 
should return the same result as the unboxed version, or (if the whole 
point is to give good performance and so we don't want want users to be 
able to accidentally use the unboxed versions) it should throw at 
compile-time for boxed args.

On Saturday, October 24, 2015 at 9:35:46 AM UTC-5, Andy Fingerhut wrote:
>
> I can't answer whether Clojure should do that.
>
> It is doing it because unchecked-multiply falls back to normal multiply, 
> i.e. *, unless both of its arguments are primitive long values.  Even boxed 
> Long values cause it to fall back to the behavior of *.  The same goes for 
> unchecked-add and unchecked-subtract.
>
>
> user=> (unchecked-multiply 2432902008176640000 21)
> -4249290049419214848
> user=> (unchecked-multiply 2432902008176640000 (Long. 21))
>
> ArithmeticException integer overflow 
>  clojure.lang.Numbers.throwIntOverflow (Numbers.java:1501)
>
> Andy
>
>
> On Fri, Oct 23, 2015 at 1:54 PM, Garrett Rowe <gmrow...@gmail.com 
> <javascript:>> wrote:
>
>> Should `unchecked-multiply` throw an exception in this case? (see also: 
>> http://stackoverflow.com/questions/33306984/why-does-my-hash-function-fail-with-arithmeticexception-integer-overflow-even/33308956#33308956
>> )
>>
>> user> (reduce unchecked-multiply (range 1 22))
>> ArithmeticException integer overflow  clojure.lang.Numbers.throwIntOverflow 
>> (Numbers.java:1388)
>>
>> The loop-recur version also fails, unless you use a type hint:
>>
>> user> (loop [n 1
>>              r (range 1 22)]
>>         (if-let [a (first r)]
>>           (recur (unchecked-multiply n a) (next r))
>>           n))
>> ArithmeticException integer overflow  clojure.lang.Numbers.throwIntOverflow 
>> (Numbers.java:1388)
>>
>> user> (loop [n 1
>>              r (range 1 22)]
>>         (if-let [^long a (first r)]
>>           (recur (unchecked-multiply n a) (next r))
>>           n))
>> -4249290049419214848
>>
>> -- 
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clo...@googlegroups.com 
>> <javascript:>
>> Note that posts from new members are moderated - please be patient with 
>> your first post.
>> To unsubscribe from this group, send email to
>> clojure+u...@googlegroups.com <javascript:>
>> 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+u...@googlegroups.com <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
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.

Reply via email to