Hi all! I encountered some corner cases where overflow checking for "-" doesn't work as I would expect:
user=> (- Integer/MAX_VALUE Integer/MIN_VALUE) -1 user=> (- Long/MAX_VALUE Long/MIN_VALUE) -1 The problem seems to be that negating MIN_VALUE yields MIN_VALUE again, so it slips through the overflow check (see below). Shall I add that to the issues list? Kind regards, achim src/jvm/clojure/lang/Numbers.java =================================================================== --- src/jvm/clojure/lang/Numbers.java (revision 1205) +++ src/jvm/clojure/lang/Numbers.java (working copy) @@ -1740,7 +1740,7 @@ static public int minus(int x, int y){ int ret = x - y; - if ((ret ^ x) < 0 && (ret ^ -y) < 0) + if (((ret ^ x) < 0 && (ret ^ -y) < 0) || (y == Integer.MIN_VALUE)) return throwIntOverflow(); return ret; } @@ -1847,7 +1847,7 @@ static public long minus(long x, long y){ long ret = x - y; - if ((ret ^ x) < 0 && (ret ^ -y) < 0) + if (((ret ^ x) < 0 && (ret ^ -y) < 0) || (y == Long.MIN_VALUE)) return throwIntOverflow(); return ret; } --~--~---------~--~----~------------~-------~--~----~ 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 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 -~----------~----~----~----~------~----~------~--~---