The difference is MAX_VALUE is a primitive int, but 1 (any literal) is an
Integer.

user> Integer/MAX_VALUE
2147483647
user> (inc 2147483647)
2147483648

But, I agree there is inconsistency. They should all check, except for the
unchecked-* fns.

user> (* Double/MAX_VALUE Double/MAX_VALUE)
Infinity
user> (* Integer/MAX_VALUE Integer/MAX_VALUE)
#<CompilerException java.lang.ArithmeticException: integer overflow
(NO_SOURCE_FILE:0)>

Since multiple for long and int checks for overflow, shouldn't multiple for
double and float check for Infinity?  With that, then
unchecked_multiple(double, double) is missing.

Other edge cases for numbers:
http://groups.google.com/group/clojure-dev/browse_thread/thread/6248584b202045e4

-Mike

On Fri, Aug 14, 2009 at 2:37 AM, Seth <seth.schroe...@gmail.com> wrote:

>
> Is there a historical reason why (inc) and (dec) overflow instead of
> automatically promoting from Integer to Long when crossing
> Integer.MAX_VALUE or Integer.MIN_VALUE? The latter would be consistent
> with (+) and (-).
>
> user=> (inc Integer/MAX_VALUE)
> java.lang.ArithmeticException: integer overflow (NO_SOURCE_FILE:0)
> user=> (dec Integer/MIN_VALUE)
> java.lang.ArithmeticException: integer overflow (NO_SOURCE_FILE:0)
> user=> (+ 1 Integer/MAX_VALUE)
> 2147483648
> user=> (- Integer/MIN_VALUE 1)
> -2147483649
>
> user=> (.getClass (+ 1 Integer/MAX_VALUE))
> java.lang.Long
>
> Here is what the docs say. If this is intentional it might be worth
> noting in the docs.
>
> -------------------------
> clojure.core/inc
> ([x])
>  Returns a number one greater than num.
>
> I'm using Clojure 1.1 alpha (most recent commit is
> 2098f5d57ecf3affb09a4cdaf2e01ad4de861eef), java build "1.6.0_13-
> b03-211"
> >
>

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

Reply via email to