Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Bug? overflow check in Numbers.minus
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Achim Passen  
View profile  
 More options Jan 8 2009, 2:07 pm
From: Achim Passen <achim.pas...@gmail.com>
Date: Thu, 8 Jan 2009 20:07:52 +0100
Local: Thurs, Jan 8 2009 2:07 pm
Subject: Bug? overflow check in Numbers.minus
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 must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chouser  
View profile  
 More options Jan 9 2009, 11:25 pm
From: Chouser <chou...@gmail.com>
Date: Fri, 9 Jan 2009 23:25:06 -0500
Local: Fri, Jan 9 2009 11:25 pm
Subject: Re: Bug? overflow check in Numbers.minus

I think you should go ahead.  I don't see how this could not be a bug.

--Chouser


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Frantisek Sodomka  
View profile  
 More options Jan 29 2009, 10:32 am
From: Frantisek Sodomka <fsodo...@gmail.com>
Date: Thu, 29 Jan 2009 07:32:12 -0800 (PST)
Local: Thurs, Jan 29 2009 10:32 am
Subject: Re: Bug? overflow check in Numbers.minus
user=> (- Integer/MAX_VALUE Integer/MIN_VALUE)
java.lang.ArithmeticException: integer overflow (NO_SOURCE_FILE:0)
user=> (- Long/MAX_VALUE Long/MIN_VALUE)
java.lang.ArithmeticException: integer overflow (NO_SOURCE_FILE:0)

Is this behavior correct?

Frantisek

On Jan 10, 5:25 am, Chouser <chou...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »