From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.5 required=5.0 tests=AWL,HTML_10_20,HTML_MESSAGE, SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id 9E8CBBC69 for ; Thu, 29 Mar 2007 18:27:12 +0200 (CEST) Received: from wr-out-0506.google.com (wr-out-0506.google.com [64.233.184.232]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l2TGRB8w022877 for ; Thu, 29 Mar 2007 18:27:12 +0200 Received: by wr-out-0506.google.com with SMTP id 69so262462wra for ; Thu, 29 Mar 2007 09:27:06 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:sender:to:subject:mime-version:content-type:x-google-sender-auth; b=LGoHhLarwsZUutavQ2YPAPNSUAqn+MgpOx3/P8H08ze48tKvMRA4g3rNO2mvWYHzoD84VgIm4aqfeXMmmlOq46AZtnRMBLbcmrf4ReJxpfeF4SNP1/tQmze0gxBsgV0ZT42tt0WooH6v5+bye8a4Jbyume6+5WoU+72hJr45kmA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:sender:to:subject:mime-version:content-type:x-google-sender-auth; b=Uq+UHpG55tR4kjwmRNxcvf3Fb2Gt6HCetiUX/My5zcsLpbfYmupVP8MOZHEDEEd5MKcaRBn2Otk1UXjrDrGLx/5J/a9CvgHXUlfJjnpIK8zekfwzrh3jk3rpdf6y/5gpTU89/hoOcRnHkckoVIpC8Qn4IgNN27ZWV0cLvzfYg4E= Received: by 10.115.76.1 with SMTP id d1mr304742wal.1175185625510; Thu, 29 Mar 2007 09:27:05 -0700 (PDT) Received: by 10.115.55.5 with HTTP; Thu, 29 Mar 2007 09:27:05 -0700 (PDT) Message-ID: <891bd3390703290927o4e1c6bb5gf8f562fedbc70096@mail.gmail.com> Date: Thu, 29 Mar 2007 12:27:05 -0400 From: "Yaron Minsky" Sender: yminsky@gmail.com To: caml-list Subject: int_of_string bug MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_48731_4892792.1175185625425" X-Google-Sender-Auth: e8c280a7bf1a98c7 X-Miltered: at discorde with ID 460BE8DF.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; yaron:01 minsky:01 yminsky:01 bug:01 bug:01 lexer:01 lexer:01 int:01 int:01 cornell:01 caml:02 caml:02 string:02 string:02 seems:03 ------=_Part_48731_4892792.1175185625425 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline So, there's a weird int_of_string bug where positive decimal numbers are sometimes read in as negative numbers without error. Here's the bug: http://caml.inria.fr/mantis/view.php?id=0004210 This has been marked as "wontfix" in the bug database because apparently there's some weird spot in the lexer that depends on the wrong behavior of int_of_string. First of all, people should be aware of this behavior and should defend against it in their code. Secondly, the justification for not fixing it seems really thin. The behavior seems obviously wrong, and it's hard to see why one wouldn't simply fix the lexer (perhaps by providing an alternate broken implementation of int_of_string) and leave the ordinary int_of_string where it is. y ------=_Part_48731_4892792.1175185625425 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline So, there's a weird int_of_string bug where positive decimal numbers are sometimes read in as negative numbers without error.  Here's the bug:

http://caml.inria.fr/mantis/view.php?id=0004210

This has been marked as "wontfix" in the bug database because apparently there's some weird spot in the lexer that depends on the wrong behavior of int_of_string. 

First of all, people should be aware of this behavior and should defend against it in their code.  Secondly, the justification for not fixing it seems really thin.  The behavior seems obviously wrong, and it's hard to see why one wouldn't simply fix the lexer (perhaps by providing an alternate broken implementation of int_of_string) and leave the ordinary int_of_string where it is.

y
------=_Part_48731_4892792.1175185625425-- From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 2AC44BC69 for ; Thu, 29 Mar 2007 23:29:35 +0200 (CEST) Received: from einhorn.in-berlin.de (einhorn.in-berlin.de [192.109.42.8]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l2TLTYLK032066 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL) for ; Thu, 29 Mar 2007 23:29:34 +0200 X-Envelope-From: oliver@first.in-berlin.de X-Envelope-To: Received: from first (dslb-088-073-123-088.pools.arcor-ip.net [88.73.123.88]) (authenticated bits=0) by einhorn.in-berlin.de (8.13.6/8.13.6/Debian-1) with ESMTP id l2TLTXb6024461 for ; Thu, 29 Mar 2007 23:29:33 +0200 Received: by first (Postfix, from userid 501) id 9CC6939C2C8; Thu, 29 Mar 2007 23:29:31 +0200 (CEST) Date: Thu, 29 Mar 2007 23:29:31 +0200 From: Oliver Bandel To: caml-list@inria.fr Subject: Re: [Caml-list] int_of_string bug Message-ID: <20070329212931.GG6843@first.in-berlin.de> References: <891bd3390703290927o4e1c6bb5gf8f562fedbc70096@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <891bd3390703290927o4e1c6bb5gf8f562fedbc70096@mail.gmail.com> User-Agent: Mutt/1.5.6i X-Scanned-By: MIMEDefang_at_IN-Berlin_e.V. on 192.109.42.8 X-Miltered: at concorde with ID 460C2FBE.002 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; bandel:01 in-berlin:01 bug:01 yaron:01 minsky:01 bug:01 lexer:01 bandel:01 wrote:01 oliver:01 oliver:01 exception:01 caml-list:01 int:01 int:01 On Thu, Mar 29, 2007 at 12:27:05PM -0400, Yaron Minsky wrote: > So, there's a weird int_of_string bug where positive decimal numbers are > sometimes read in as negative numbers without error. Here's the bug: > > http://caml.inria.fr/mantis/view.php?id=0004210 > > This has been marked as "wontfix" in the bug database because apparently > there's some weird spot in the lexer that depends on the wrong behavior of > int_of_string. [...] Oh, that's bad. :( But btw. it's also bad that, when overflowing of int occurs, no exception is thrown. :( Ciao, Oliver Bandel From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.7 required=5.0 tests=AWL,HTML_MESSAGE,SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id BA9BBBC69 for ; Fri, 30 Mar 2007 02:26:07 +0200 (CEST) Received: from ik-out-1112.google.com (ik-out-1112.google.com [66.249.90.180]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l2U0Q7cw003440 for ; Fri, 30 Mar 2007 02:26:07 +0200 Received: by ik-out-1112.google.com with SMTP id c29so274620ika for ; Thu, 29 Mar 2007 17:26:07 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:references:x-google-sender-auth; b=dfN2sFz65Xs5ZskWFs0QmRM7nkmd69ALDrCcXjD+BIHXpMOMvAgJgaU9Puh/JFj0Ca0eKdStCWCtwbZd2ga6yqcezQx/HRIHLRB+VLEGxGlSyGZxooi5SphW80OdmhXehY3/UB4/pvbGFB+bT0tcoD6DwLzo0jdBz9yoQ/NkzJY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:references:x-google-sender-auth; b=Ojd74NzacjCKMors1EvGKb5YXVekJ5vc+dobVPD7MQp3oXTL+WL0UaqFtHF34W0iUe74DS3woejSI+W924cyISWAkBDCt4sTjabRbS0TBlTLVRZQIGhXpQwXg2erdMlrNLZeIRgeryfa8RxwvhvtgTPr8H5fLvTjSPVrFN4GV0A= Received: by 10.115.76.1 with SMTP id d1mr490789wal.1175214366059; Thu, 29 Mar 2007 17:26:06 -0700 (PDT) Received: by 10.115.55.5 with HTTP; Thu, 29 Mar 2007 17:26:06 -0700 (PDT) Message-ID: <891bd3390703291726ue71cfa6re8d4c3d66520e4d9@mail.gmail.com> Date: Thu, 29 Mar 2007 20:26:06 -0400 From: "Yaron Minsky" Sender: yminsky@gmail.com To: "Oliver Bandel" Subject: Re: [Caml-list] int_of_string bug Cc: caml-list@inria.fr In-Reply-To: <20070329212931.GG6843@first.in-berlin.de> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_55295_4260355.1175214366013" References: <891bd3390703290927o4e1c6bb5gf8f562fedbc70096@mail.gmail.com> <20070329212931.GG6843@first.in-berlin.de> X-Google-Sender-Auth: 1b0d1e367ac89a57 X-Miltered: at discorde with ID 460C591F.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; yaron:01 minsky:01 yminsky:01 bug:01 bandel:01 in-berlin:01 yaron:01 minsky:01 bug:01 lexer:01 bandel:01 beginner's:01 ocaml:01 in-berlin:01 lexer:01 ------=_Part_55295_4260355.1175214366013 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 3/29/07, Oliver Bandel wrote: > > On Thu, Mar 29, 2007 at 12:27:05PM -0400, Yaron Minsky wrote: > > So, there's a weird int_of_string bug where positive decimal numbers are > > sometimes read in as negative numbers without error. Here's the bug: > > > > http://caml.inria.fr/mantis/view.php?id=0004210 > > > > This has been marked as "wontfix" in the bug database because apparently > > there's some weird spot in the lexer that depends on the wrong behavior > of > > int_of_string. > [...] > > Oh, that's bad. :( > > But btw. it's also bad that, when overflowing of int occurs, no > exception is thrown. :( That's a problem too, but there is at least a defensible reason for that, which is that it is expensive to get integer overflow to throw an exception. Ciao, > Oliver Bandel > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > ------=_Part_55295_4260355.1175214366013 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline

On 3/29/07, Oliver Bandel <oliver@first.in-berlin.de> wrote:
On Thu, Mar 29, 2007 at 12:27:05PM -0400, Yaron Minsky wrote:
> So, there's a weird int_of_string bug where positive decimal numbers are
> sometimes read in as negative numbers without error.  Here's the bug:
>
> http://caml.inria.fr/mantis/view.php?id=0004210
>
> This has been marked as "wontfix" in the bug database because apparently
> there's some weird spot in the lexer that depends on the wrong behavior of
> int_of_string.
[...]

Oh, that's bad. :(

But btw. it's also bad that, when overflowing of int occurs, no
exception is thrown. :(

That's a problem too, but there is at least a defensible reason for that, which is that it is expensive to get integer overflow to throw an exception.

Ciao,
   Oliver Bandel

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

------=_Part_55295_4260355.1175214366013-- From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id 22C68BC69 for ; Fri, 30 Mar 2007 03:08:36 +0200 (CEST) Received: from bsd4.nyct.net (mail-out4.nyct.net [216.139.141.4]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l2U18Y0K009690 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Fri, 30 Mar 2007 03:08:35 +0200 Received: from [216.139.138.21] ([216.139.138.21]) by bsd4.nyct.net (8.13.4/8.13.4) with ESMTP id l2U18MsN025986; Thu, 29 Mar 2007 21:08:25 -0400 (EDT) (envelope-from bhurt@spnz.org) Date: Thu, 29 Mar 2007 21:21:40 -0400 (EDT) From: Brian Hurt X-X-Sender: bhurt@localhost To: Yaron Minsky Cc: caml-list Subject: Re: [Caml-list] int_of_string bug In-Reply-To: <891bd3390703290927o4e1c6bb5gf8f562fedbc70096@mail.gmail.com> Message-ID: References: <891bd3390703290927o4e1c6bb5gf8f562fedbc70096@mail.gmail.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Miltered: at discorde with ID 460C6312.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; bug:01 yaron:01 minsky:01 bug:01 ocaml:01 ocaml's:01 2007,:98 wrote:01 integer:01 caml-list:01 int:01 int:01 argument:02 caml:02 string:02 On Thu, 29 Mar 2007, Yaron Minsky wrote: > So, there's a weird int_of_string bug where positive decimal numbers are > sometimes read in as negative numbers without error. Here's the bug: > > http://caml.inria.fr/mantis/view.php?id=0004210 I'm actually not sure this is a bug either. Note that ocaml will quite happily compute max_int+1 without an error either. Wether this behavior (silent wrap around) is correct or not is another argument. Elsewhere I have opinioned that the only purpose for having more than one type of integer in your programming language is so that programmers can pick the wrong one. But I'm widely known to be a heretic. Ocaml's behavior is, at least, *consistent*. Brian From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.5 required=5.0 tests=AWL,HTML_MESSAGE,SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id 4C976BC69 for ; Fri, 30 Mar 2007 03:26:06 +0200 (CEST) Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.172]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l2U1Q5fL012465 for ; Fri, 30 Mar 2007 03:26:06 +0200 Received: by ug-out-1314.google.com with SMTP id q2so745002uge for ; Thu, 29 Mar 2007 18:26:05 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:references:x-google-sender-auth; b=BlsX/qHRsaJSiLeoNgBWF9mRWLdFdezpFjNIaoahHujYTLTHBJ2OoDR/VvDkeNb2iSOMjDtKc6WuddlfgGXsGG2NetWMBx4u4nGMk5g/pekrG6hhC8wSAyQFOHrtMIIQ2kduxJaCqTUa/YDPCF+tURbd1cOiMAYvkOW8Iwrgof0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version:content-type:references:x-google-sender-auth; b=BJLM2Sd1es0H0YkjOfqqWPhGtXInTOFNUgLTd0IlHjKQr2FWuRFrcW6qN/vp5lZvyHZypomYSSypAXjnUrqOBgNwj0eHmmWHuYjcN2rVEmacb7M37ayck74EPWnCB1IU33LTN037wyufziMBSfhAN0DzH6HplBGUM+QDC9VqVVk= Received: by 10.114.208.8 with SMTP id f8mr526641wag.1175217964628; Thu, 29 Mar 2007 18:26:04 -0700 (PDT) Received: by 10.115.55.5 with HTTP; Thu, 29 Mar 2007 18:26:04 -0700 (PDT) Message-ID: <891bd3390703291826k6002ef28i93bca9944cdbceee@mail.gmail.com> Date: Thu, 29 Mar 2007 21:26:04 -0400 From: "Yaron Minsky" Sender: yminsky@gmail.com To: "Brian Hurt" Subject: Re: [Caml-list] int_of_string bug Cc: caml-list In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_55827_32960381.1175217964552" References: <891bd3390703290927o4e1c6bb5gf8f562fedbc70096@mail.gmail.com> X-Google-Sender-Auth: 362232b43a7f1640 X-Miltered: at discorde with ID 460C672D.001 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; yaron:01 minsky:01 yminsky:01 bug:01 ocaml's:01 beginner's:01 ocaml:01 bug:01 ocaml's:01 beginner's:01 ocaml:01 beginners:01 beginners:01 wrote:01 wrote:01 ------=_Part_55827_32960381.1175217964552 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 3/29/07, Brian Hurt wrote: > > > Wether this behavior (silent wrap around) is correct or not is another > argument. Elsewhere I have opinioned that the only purpose for having > more than one type of integer in your programming language is so that > programmers can pick the wrong one. But I'm widely known to be a heretic. > > Ocaml's behavior is, at least, *consistent*. Not really all that consistent: # int_of_string "1073741824";; - : int = -1073741824 # int_of_string "1073741825";; Exception: Failure "int_of_string". # y Brian > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > ------=_Part_55827_32960381.1175217964552 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On 3/29/07, Brian Hurt <bhurt@spnz.org> wrote:

Wether this behavior (silent wrap around) is correct or not is another
argument.  Elsewhere I have opinioned that the only purpose for having
more than one type of integer in your programming language is so that
programmers can pick the wrong one.  But I'm widely known to be a heretic.

Ocaml's behavior is, at least, *consistent*.

Not really all that consistent:

# int_of_string "1073741824";;
- : int = -1073741824
# int_of_string "1073741825";;
Exception: Failure "int_of_string".

y

Brian

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

------=_Part_55827_32960381.1175217964552-- From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id 2D422BC69 for ; Fri, 30 Mar 2007 06:29:15 +0200 (CEST) Received: from ipmail02.adl2.internode.on.net (ipmail02.adl2.internode.on.net [203.16.214.141]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l2U4TBu6006948 for ; Fri, 30 Mar 2007 06:29:12 +0200 Received: from ppp36-111.lns2.syd6.internode.on.net (HELO [192.168.1.201]) ([59.167.36.111]) by ipmail02.adl2.internode.on.net with ESMTP; 30 Mar 2007 13:53:55 +0930 X-IronPort-AV: i="4.14,350,1170595800"; d="scan'208"; a="104055551:sNHT4348174950" Subject: Re: [Caml-list] int_of_string bug From: skaller To: Yaron Minsky Cc: Brian Hurt , caml-list In-Reply-To: <891bd3390703291826k6002ef28i93bca9944cdbceee@mail.gmail.com> References: <891bd3390703290927o4e1c6bb5gf8f562fedbc70096@mail.gmail.com> <891bd3390703291826k6002ef28i93bca9944cdbceee@mail.gmail.com> Content-Type: text/plain Date: Fri, 30 Mar 2007 14:23:51 +1000 Message-Id: <1175228631.18890.4.camel@rosella.wigram> Mime-Version: 1.0 X-Mailer: Evolution 2.8.1 Content-Transfer-Encoding: 7bit X-Miltered: at discorde with ID 460C9217.001 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; bug:01 yaron:01 minsky:01 ocaml's:01 ledit:01 ocaml:01 sourceforge:01 wrote:01 wrote:01 integer:01 exception:01 caml-list:01 dev:01 int:01 int:01 On Thu, 2007-03-29 at 21:26 -0400, Yaron Minsky wrote: > On 3/29/07, Brian Hurt wrote: > > Wether this behavior (silent wrap around) is correct or not is > another > argument. Elsewhere I have opinioned that the only purpose > for having > more than one type of integer in your programming language is > so that > programmers can pick the wrong one. But I'm widely known to > be a heretic. > > Ocaml's behavior is, at least, *consistent*. > > Not really all that consistent: > > # int_of_string "1073741824";; > - : int = -1073741824 > # int_of_string "1073741825";; > Exception: Failure "int_of_string". > # skaller@rosella:/work/felix/svn/felix/felix/trunk$ ledit ocaml Objective Caml version 3.10+dev25 (2007-03-26) # int_of_string "1073741824";; - : int = 1073741824 # int_of_string "1073741825";; - : int = 1073741825 -- John Skaller Felix, successor to C++: http://felix.sf.net From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 38B41BC69 for ; Fri, 30 Mar 2007 07:59:48 +0200 (CEST) Received: from smtp.syd.people.net.au (smtp.syd.people.net.au [218.214.225.98]) by concorde.inria.fr (8.13.6/8.13.6) with SMTP id l2U5xgqH025834 for ; Fri, 30 Mar 2007 07:59:47 +0200 Received: (qmail 9440 invoked from network); 30 Mar 2007 05:59:47 -0000 Received: from unknown (HELO coltrane.mega-nerd.net) (218.214.64.136) by smtp.syd.people.net.au with SMTP; 30 Mar 2007 05:59:47 -0000 Received: from coltrane (coltrane [192.168.1.101]) by coltrane.mega-nerd.net (Postfix) with SMTP id 29F897ADA for ; Fri, 30 Mar 2007 15:59:37 +1000 (EST) Date: Fri, 30 Mar 2007 15:59:36 +1000 From: Erik de Castro Lopo To: caml-list Subject: Re: [Caml-list] int_of_string bug Message-Id: <20070330155936.86654f51.mle+ocaml@mega-nerd.com> In-Reply-To: <1175228631.18890.4.camel@rosella.wigram> References: <891bd3390703290927o4e1c6bb5gf8f562fedbc70096@mail.gmail.com> <891bd3390703291826k6002ef28i93bca9944cdbceee@mail.gmail.com> <1175228631.18890.4.camel@rosella.wigram> Organization: Erik Conspiracy Secret Labs X-Mailer: Sylpheed version 2.3.0beta5 (GTK+ 2.8.20; i486-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 460CA74E.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ocaml:01 bug:01 yaron:01 minsky:01 wrote:01 wrote:01 exception:01 behaviour:01 caml-list:01 int:01 int:01 argument:02 string:02 string:02 erik:04 skaller wrote: > On Thu, 2007-03-29 at 21:26 -0400, Yaron Minsky wrote: > > # int_of_string "1073741824";; > > - : int = -1073741824 > > # int_of_string "1073741825";; > > Exception: Failure "int_of_string". Thats the behaviour on 32 bit systems. > # int_of_string "1073741824";; > - : int = 1073741824 > # int_of_string "1073741825";; > - : int = 1073741825 But 64 bit systems get it right. Erik -- +-----------------------------------------------------------+ Erik de Castro Lopo +-----------------------------------------------------------+ "Java, the best argument for Smalltalk since C++." -- Frank Winkler From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id B1BB1BC69 for ; Fri, 30 Mar 2007 08:23:38 +0200 (CEST) Received: from ipmail02.adl2.internode.on.net (ipmail02.adl2.internode.on.net [203.16.214.141]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l2U6NaLQ022713 for ; Fri, 30 Mar 2007 08:23:37 +0200 Received: from ppp36-111.lns2.syd6.internode.on.net (HELO [192.168.1.201]) ([59.167.36.111]) by ipmail02.adl2.internode.on.net with ESMTP; 30 Mar 2007 15:52:59 +0930 X-IronPort-AV: i="4.14,350,1170595800"; d="scan'208"; a="104111258:sNHT4103015749" Subject: Re: [Caml-list] int_of_string bug From: skaller To: caml-list In-Reply-To: <20070330155936.86654f51.mle+ocaml@mega-nerd.com> References: <891bd3390703290927o4e1c6bb5gf8f562fedbc70096@mail.gmail.com> <891bd3390703291826k6002ef28i93bca9944cdbceee@mail.gmail.com> <1175228631.18890.4.camel@rosella.wigram> <20070330155936.86654f51.mle+ocaml@mega-nerd.com> Content-Type: text/plain Date: Fri, 30 Mar 2007 16:22:54 +1000 Message-Id: <1175235774.18890.67.camel@rosella.wigram> Mime-Version: 1.0 X-Mailer: Evolution 2.8.1 Content-Transfer-Encoding: 7bit X-Miltered: at discorde with ID 460CACE8.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; bug:01 yaron:01 minsky:01 parser:01 ocaml:01 compiler:01 lexing:01 'string:01 arrays:01 ocaml:01 bug:01 -unsafe:01 wildcard:01 sourceforge:01 wrote:01 On Fri, 2007-03-30 at 15:59 +1000, Erik de Castro Lopo wrote: > skaller wrote: > > > On Thu, 2007-03-29 at 21:26 -0400, Yaron Minsky wrote: > > > # int_of_string "1073741824";; > > > - : int = -1073741824 > > > # int_of_string "1073741825";; > > > Exception: Failure "int_of_string". > > Thats the behaviour on 32 bit systems. > > > # int_of_string "1073741824";; > > - : int = 1073741824 > > # int_of_string "1073741825";; > > - : int = 1073741825 > > But 64 bit systems get it right. The point being .. the behaviour for large values is platform independent anyhow, so in the abstract you can say the behaviour is undefined for large values, where 'large' isn't specified. If you want to get it RIGHT: if you have a user input string possibly containing digits, and you want to convert it, you must already write a parser to parse the input, so you won't be using int_of_string anyhow. If the input was generated (say by another Ocaml program), then it will already be correct. In the Felix compiler, after lexing 'string of digits' I use the Big_int module to convert to an integer: that behaviour is platform independent. If I really want an int (say for indexing), and there's a risk of the conversion overflowing .. there's a risk that even without overflowing the data is wrong and will blow up, eg .. I'm not going to be indexing arrays with max_int elements .. :) If I really want to check, I'll use an application specific bound such as 16000, and check the big_int against that before converting. Thus, all the operations are deterministic and platform independent if you do things properly. So the 'bug' in string_of_int is just an inconvenience. IMHO there is a 'bug' in some Ocaml documentation, where the abstract language is not clearly distinguished from the implementation. Throwing exceptions on error should generally NOT be considered a specified part of the language. Undefined behaviour is sometimes the right specification because it allows superior optimisation and prevents programmers relying on exceptions. This doesn't prevent the implementation throwing them, it just means catching them locally in your code is a bug (because you can't be sure they will be thrown). Bounds violations are a good example of this, and indeed since Ocaml allows -unsafe switch to disable bound checks you'd better NOT rely on catching them. The same applies to match failures -- use a wildcard if you want to catch unmatched cases (otherwise be willing to sketch a proof to your boss that there can't be a violation :) -- John Skaller Felix, successor to C++: http://felix.sf.net From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id E5688BC69 for ; Fri, 30 Mar 2007 09:31:04 +0200 (CEST) Received: from mail.enyo.de (mail.enyo.de [212.9.189.167]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l2U7V3eb032253 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO) for ; Fri, 30 Mar 2007 09:31:04 +0200 Received: from deneb.vpn.enyo.de ([212.9.189.177] helo=deneb.enyo.de) by mail.enyo.de with esmtp id 1HXBZa-0002NC-M2; Fri, 30 Mar 2007 09:30:58 +0200 Received: from fw by deneb.enyo.de with local (Exim 4.63) (envelope-from ) id 1HXBZX-0001zX-Qd; Fri, 30 Mar 2007 09:30:55 +0200 From: Florian Weimer To: "Yaron Minsky" Cc: "Oliver Bandel" , caml-list@inria.fr Subject: Re: [Caml-list] int_of_string bug References: <891bd3390703290927o4e1c6bb5gf8f562fedbc70096@mail.gmail.com> <20070329212931.GG6843@first.in-berlin.de> <891bd3390703291726ue71cfa6re8d4c3d66520e4d9@mail.gmail.com> Date: Fri, 30 Mar 2007 09:30:55 +0200 In-Reply-To: <891bd3390703291726ue71cfa6re8d4c3d66520e4d9@mail.gmail.com> (Yaron Minsky's message of "Thu, 29 Mar 2007 20:26:06 -0400") Message-ID: <878xdfmbm8.fsf@mid.deneb.enyo.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Miltered: at discorde with ID 460CBCB8.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; bug:01 yaron:01 minsky:01 integer:01 exception:01 caml-list:01 short:01 int:01 string:02 florian:03 overflow:03 overhead:04 problem:05 sequences:05 uses:06 * Yaron Minsky: > That's a problem too, but there is at least a defensible reason for > that, which is that it is expensive to get integer overflow to throw > an exception. i386 and amd64 have hardware support for that, so it's not very expensive. There are pretty short RISC sequences for the checks, too. MLton uses the i386 hardware support, and I think you can disable the checks, so measuring the overhead shouldn't be too hard. From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id A55D4BC69 for ; Fri, 30 Mar 2007 10:44:38 +0200 (CEST) Received: from ipmail02.adl2.internode.on.net (ipmail02.adl2.internode.on.net [203.16.214.141]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l2U8iau0024582 for ; Fri, 30 Mar 2007 10:44:37 +0200 Received: from ppp36-111.lns2.syd6.internode.on.net (HELO [192.168.1.201]) ([59.167.36.111]) by ipmail02.adl2.internode.on.net with ESMTP; 30 Mar 2007 18:14:34 +0930 X-IronPort-AV: i="4.14,352,1170595800"; d="scan'208"; a="104166833:sNHT23842833" Subject: Re: [Caml-list] int_of_string bug From: skaller To: Florian Weimer Cc: Yaron Minsky , Oliver Bandel , caml-list@inria.fr In-Reply-To: <878xdfmbm8.fsf@mid.deneb.enyo.de> References: <891bd3390703290927o4e1c6bb5gf8f562fedbc70096@mail.gmail.com> <20070329212931.GG6843@first.in-berlin.de> <891bd3390703291726ue71cfa6re8d4c3d66520e4d9@mail.gmail.com> <878xdfmbm8.fsf@mid.deneb.enyo.de> Content-Type: text/plain Date: Fri, 30 Mar 2007 18:44:31 +1000 Message-Id: <1175244271.22118.10.camel@rosella.wigram> Mime-Version: 1.0 X-Mailer: Evolution 2.8.1 Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 460CCDF4.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; bug:01 0200,:01 yaron:01 minsky:01 ocaml:01 integers:01 sourceforge:01 wrote:01 integer:01 exception:01 caml-list:01 short:01 int:01 string:02 florian:03 On Fri, 2007-03-30 at 09:30 +0200, Florian Weimer wrote: > * Yaron Minsky: > > > That's a problem too, but there is at least a defensible reason for > > that, which is that it is expensive to get integer overflow to throw > > an exception. > > i386 and amd64 have hardware support for that, so it's not very > expensive. There are pretty short RISC sequences for the checks, too. > > MLton uses the i386 hardware support, and I think you can disable the > checks, so measuring the overhead shouldn't be too hard. But there is a difference you may have missed: Ocaml integers are 31 or 63 bits, not 32 or 64 bits. -- John Skaller Felix, successor to C++: http://felix.sf.net From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.1 required=5.0 tests=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id CA22EBC69 for ; Fri, 30 Mar 2007 11:01:24 +0200 (CEST) Received: from triton.rz.uni-saarland.de (triton.rz.uni-saarland.de [134.96.7.25]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l2U91O5N028124 for ; Fri, 30 Mar 2007 11:01:24 +0200 Received: from mail.cs.uni-sb.de (mail.cs.uni-sb.de [134.96.254.200]) by triton.rz.uni-saarland.de (8.12.11.20060614/8.12.10) with ESMTP id l2U90S1i6591276; Fri, 30 Mar 2007 11:00:28 +0200 (CEST) Received: from mail.ps.uni-sb.de (james.ps.uni-sb.de [134.96.186.68]) by mail.cs.uni-sb.de (8.14.0/2007012900) with ESMTP id l2U90RWA016125; Fri, 30 Mar 2007 11:00:27 +0200 (CEST) Received: from groove.ps.uni-sb.de ([134.96.186.112]) by mail.ps.uni-sb.de with esmtp (Exim 4.50) id 1HXCy8-0004xN-Po; Fri, 30 Mar 2007 11:00:27 +0200 Message-ID: <460CD180.6080404@ps.uni-sb.de> Date: Fri, 30 Mar 2007 10:59:44 +0200 From: Andreas Rossberg User-Agent: Thunderbird 1.5.0.5 (X11/20060812) MIME-Version: 1.0 To: skaller Cc: Florian Weimer , Oliver Bandel , Yaron Minsky , caml-list@inria.fr References: <891bd3390703290927o4e1c6bb5gf8f562fedbc70096@mail.gmail.com> <20070329212931.GG6843@first.in-berlin.de> <891bd3390703291726ue71cfa6re8d4c3d66520e4d9@mail.gmail.com> <878xdfmbm8.fsf@mid.deneb.enyo.de> <1175244271.22118.10.camel@rosella.wigram> In-Reply-To: <1175244271.22118.10.camel@rosella.wigram> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-SA-Exim-Connect-IP: 134.96.186.112 X-SA-Exim-Mail-From: rossberg@ps.uni-sb.de Subject: Re: [Caml-list] int_of_string bug X-SA-Exim-Version: 4.2 (built Thu, 03 Mar 2005 10:44:12 +0100) X-SA-Exim-Scanned: Yes (on mail.ps.uni-sb.de) X-AntiVirus: checked by AntiVir Milter (version: 1.1.3-1; AVE: 7.3.1.46; VDF: 6.38.0.146; host: AntiVir1) X-Miltered: at concorde with ID 460CD1E4.001 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; rossberg:01 rossberg:01 bug:01 ocaml:01 integers:01 non-issue:01 wrote:01 integer:01 exception:01 caml-list:01 ints:01 andreas:01 andreas:01 short:01 int:01 skaller wrote: >> >>> That's a problem too, but there is at least a defensible reason for >>> that, which is that it is expensive to get integer overflow to throw >>> an exception. >> i386 and amd64 have hardware support for that, so it's not very >> expensive. There are pretty short RISC sequences for the checks, too. >> >> MLton uses the i386 hardware support, and I think you can disable the >> checks, so measuring the overhead shouldn't be too hard. > > But there is a difference you may have missed: Ocaml integers > are 31 or 63 bits, not 32 or 64 bits. But it uses the most significant 31/63 bits for ints, so that becomes a non-issue. ;-) -- Andreas Rossberg, rossberg@ps.uni-sb.de From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 5E12DBC69 for ; Fri, 30 Mar 2007 11:20:56 +0200 (CEST) Received: from ipmail02.adl2.internode.on.net (ipmail02.adl2.internode.on.net [203.16.214.141]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l2U9KsmO032001 for ; Fri, 30 Mar 2007 11:20:55 +0200 Received: from ppp36-111.lns2.syd6.internode.on.net (HELO [192.168.1.201]) ([59.167.36.111]) by ipmail02.adl2.internode.on.net with ESMTP; 30 Mar 2007 18:50:50 +0930 X-IronPort-AV: i="4.14,352,1170595800"; d="scan'208"; a="104176316:sNHT33683727" Subject: Re: [Caml-list] int_of_string bug From: skaller To: Andreas Rossberg Cc: Florian Weimer , Yaron Minsky , Oliver Bandel , caml-list@inria.fr In-Reply-To: <460CD180.6080404@ps.uni-sb.de> References: <891bd3390703290927o4e1c6bb5gf8f562fedbc70096@mail.gmail.com> <20070329212931.GG6843@first.in-berlin.de> <891bd3390703291726ue71cfa6re8d4c3d66520e4d9@mail.gmail.com> <878xdfmbm8.fsf@mid.deneb.enyo.de> <1175244271.22118.10.camel@rosella.wigram> <460CD180.6080404@ps.uni-sb.de> Content-Type: text/plain Date: Fri, 30 Mar 2007 19:20:46 +1000 Message-Id: <1175246446.22118.35.camel@rosella.wigram> Mime-Version: 1.0 X-Mailer: Evolution 2.8.1 Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 460CD676.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; bug:01 0200,:01 rossberg:01 ocaml:01 integers:01 non-issue:01 ocaml:01 sourceforge:01 wrote:01 wrote:01 integer:01 exception:01 caml-list:01 ints:01 andreas:01 On Fri, 2007-03-30 at 10:59 +0200, Andreas Rossberg wrote: > skaller wrote: > >> > >>> That's a problem too, but there is at least a defensible reason for > >>> that, which is that it is expensive to get integer overflow to throw > >>> an exception. > >> i386 and amd64 have hardware support for that, so it's not very > >> expensive. There are pretty short RISC sequences for the checks, too. > >> > >> MLton uses the i386 hardware support, and I think you can disable the > >> checks, so measuring the overhead shouldn't be too hard. > > > > But there is a difference you may have missed: Ocaml integers > > are 31 or 63 bits, not 32 or 64 bits. > > But it uses the most significant 31/63 bits for ints, so that becomes a > non-issue. ;-) For addition maybe, certainly not for multiplication: one of the operands has to be shifted right 1 place. But it depends on the code generator internal details. You could always shift BOTH operands, do the register calculation, then shift back .. in which case you'd lose overflow detection. The problem is you cannot use the carry bit after the shift back because the bit will definitely be set if the result is negative. >>From what I've seen Ocaml actually uses tricks which also might defeat detection, for example I've seen some use of LEA (load effective address) with the scale by 2 option to load and shift one bit in a single instruction. Processors are quirky about flag bits .. some set sign bit on loading and others don't, etc, so it could be quite messy. This is why C doesn't specify what happens on overflow: it would compromise performance on some processors. -- John Skaller Felix, successor to C++: http://felix.sf.net From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.3 required=5.0 tests=AWL,SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id F2C25BC6B for ; Fri, 30 Mar 2007 15:39:00 +0200 (CEST) Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.174]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l2UDd0T2001937 for ; Fri, 30 Mar 2007 15:39:00 +0200 Received: by ug-out-1314.google.com with SMTP id q2so903200uge for ; Fri, 30 Mar 2007 06:39:00 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=F1L5Aq5VRkqgbmGIPtlzUvf9B1nX/HvwyWlaEWTUGTYl4XpzKCVJRKJlateIJROyLkhbuh7hzVim+OpwOAwf2tPgAjNcTomrlfeI/YHbqqQ8hwLqxvHjMsHP055cCt2pxZL0a+lUIBuiU6PqUSanATGylYmKDeeTyqUXyF/wbj8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=GkBQIc0/HBkdtKouddSqrsYj5od2K3pFaTBQ5Kw160A6lZpjVJjTevU05ESlLJ78uM0zWmP5ZPBeRgHJZYFQT+8fOS8hdpZO8b5lgYjVxHllqyR0XqUVO+M7RSDpxrTBgHpkuMsxj8CeZiA1tW/C+pOOqAkJE0NzwrXKw8K3JIY= Received: by 10.78.193.19 with SMTP id q19mr860931huf.1175261939287; Fri, 30 Mar 2007 06:38:59 -0700 (PDT) Received: by 10.78.21.20 with HTTP; Fri, 30 Mar 2007 06:38:59 -0700 (PDT) Message-ID: Date: Fri, 30 Mar 2007 09:38:59 -0400 From: "Markus Mottl" To: "Erik de Castro Lopo" Subject: Re: [Caml-list] int_of_string bug Cc: caml-list In-Reply-To: <20070330155936.86654f51.mle+ocaml@mega-nerd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <891bd3390703290927o4e1c6bb5gf8f562fedbc70096@mail.gmail.com> <891bd3390703291826k6002ef28i93bca9944cdbceee@mail.gmail.com> <1175228631.18890.4.camel@rosella.wigram> <20070330155936.86654f51.mle+ocaml@mega-nerd.com> X-j-chkmail-Score: MSGID : 460D12F4.001 on discorde : j-chkmail score : X : 0/20 1 0.000 -> 1 X-Miltered: at discorde with ID 460D12F4.001 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; markus:01 mottl:01 markus:01 mottl:01 bug:01 ocaml:01 arises:01 nativeint:01 ocaml:01 wrote:01 integer:01 exception:01 caml-list:01 functions:01 int:01 On 3/30/07, Erik de Castro Lopo wrote: > But 64 bit systems get it right. Not really: # int_of_string "4611686018427387903";; - : int = 4611686018427387903 # int_of_string "4611686018427387904";; - : int = -4611686018427387904 # int_of_string "4611686018427387905";; Exception: Failure "int_of_string". The problem is just shifted to bigger numbers. This problem arises with all integer conversion functions, i.e. Int64.of_string, Int32.of_string, Nativeint.of_string, int_of_string. Regards Markus -- Markus Mottl http://www.ocaml.info markus.mottl@gmail.com From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.4 required=5.0 tests=SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id 0F8ECBC6B for ; Tue, 3 Apr 2007 19:51:38 +0200 (CEST) Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.168]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l33HpVt4021760 for ; Tue, 3 Apr 2007 19:51:34 +0200 Received: by ug-out-1314.google.com with SMTP id q2so411650uge for ; Tue, 03 Apr 2007 10:51:30 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:user-agent:mime-version:to:subject:references:in-reply-to:content-type:content-transfer-encoding; b=tx7nKggoa4hlrD8cXTb5anFWwBHZRqm8bq9feANK3qoboSdNJCucEUigDQVBuQr3fRUc0/Htmkco0sL7SvwBLCUbmv7c2F00TxFN/lEwIpL9Q6szte6rFNFLmrePb8CrgfTWZJiGw/lHS9hmez3vF+r1Hhk6Fyh0PaUT04vJV4c= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:user-agent:mime-version:to:subject:references:in-reply-to:content-type:content-transfer-encoding; b=YUofHIGCsl9fMmaEnkDz6ax+rwJjNIKb9/jb7ffCAwp8ls2ebUL2oHjJx6tx5K8TGNMqaNQKyzcCQPlG/MOTYyji5onIojktcDwQFcRhnwKJVar57skZwaH/hJ5sYMnHYPwyEy5hOx0u79gdgKHTk9apfRdaItFVeT6Qav2Q9rk= Received: by 10.66.232.11 with SMTP id e11mr800922ugh.1175622690812; Tue, 03 Apr 2007 10:51:30 -0700 (PDT) Received: from ?192.168.2.17? ( [62.30.232.209]) by mx.google.com with ESMTP id e23sm1520454ugd.2007.04.03.10.51.25; Tue, 03 Apr 2007 10:51:29 -0700 (PDT) Message-ID: <4612941A.9010800@gmail.com> Date: Tue, 03 Apr 2007 18:51:22 +0100 From: Toby Kelsey User-Agent: Thunderbird 1.5.0.10 (X11/20070306) MIME-Version: 1.0 To: caml-list Subject: Re: [Caml-list] int_of_string bug References: <891bd3390703290927o4e1c6bb5gf8f562fedbc70096@mail.gmail.com> <891bd3390703291826k6002ef28i93bca9944cdbceee@mail.gmail.com> <1175228631.18890.4.camel@rosella.wigram> <20070330155936.86654f51.mle+ocaml@mega-nerd.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-j-chkmail-Score: MSGID : 46129423.002 on discorde : j-chkmail score : X : 0/20 1 0.000 -> 1 X-Miltered: at discorde with ID 46129423.002 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; bug:01 markus:01 mottl:01 arises:01 nativeint:01 markus:01 bug:01 val:01 bool:01 wrote:01 integer:01 caml-list:01 functions:01 int:01 int:01 Markus Mottl wrote: > The problem is just shifted to bigger numbers. This problem arises > with all integer conversion functions, i.e. Int64.of_string, > Int32.of_string, Nativeint.of_string, int_of_string. > > Regards > Markus This bug is not just a conversion problem: # let x = 1073741824;; val x : int = -1073741824 # (x < 0) && (x >= -x);; - : bool = true Toby From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=NO_REAL_NAME autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id D826BBC0A for ; Wed, 4 Apr 2007 00:30:13 +0200 (CEST) Received: from server2.thinkcrime.de (server2.thinkcrime.de [213.133.110.149]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l33MUD6G005130 for ; Wed, 4 Apr 2007 00:30:13 +0200 Received: from hod-sarge-2005-10.lan.m-e-leypold.de (dslb-088-074-034-145.pools.arcor-ip.net [88.74.34.145]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by server2.thinkcrime.de (Postfix) with ESMTP id 16BF6488176 for ; Wed, 4 Apr 2007 00:30:16 +0200 (CEST) Received: by hod-sarge-2005-10.lan.m-e-leypold.de (Postfix, from userid 1003) id 224F7376C9; Wed, 4 Apr 2007 00:37:17 +0200 (CEST) To: caml-list Subject: Re: [Caml-list] int_of_string bug References: <891bd3390703290927o4e1c6bb5gf8f562fedbc70096@mail.gmail.com> <891bd3390703291826k6002ef28i93bca9944cdbceee@mail.gmail.com> <1175228631.18890.4.camel@rosella.wigram> <20070330155936.86654f51.mle+ocaml@mega-nerd.com> <4612941A.9010800@gmail.com> Organization: Leypold, Software-Dienstleistungen und -Beratung From: ls-ocaml-developer-2006@m-e-leypold.de Date: Wed, 04 Apr 2007 00:37:17 +0200 In-Reply-To: <4612941A.9010800@gmail.com> (Toby Kelsey's message of "Tue, 03 Apr 2007 18:51:22 +0100") Message-ID: User-Agent: Some cool user agent (SCUG) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Miltered: at discorde with ID 4612D575.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; bug:01 markus:01 mottl:01 arises:01 nativeint:01 markus:01 bug:01 val:01 bool:01 val:01 modular:01 wrote:01 integer:01 caml-list:01 writes:01 Toby Kelsey writes: > Markus Mottl wrote: > >> The problem is just shifted to bigger numbers. This problem arises >> with all integer conversion functions, i.e. Int64.of_string, >> Int32.of_string, Nativeint.of_string, int_of_string. >> Regards >> Markus > > This bug is not just a conversion problem: > > # let x = 1073741824;; > val x : int = -1073741824 > # (x < 0) && (x >= -x);; > - : bool = true # let x = - 1073741824;; val x : int = -1073741824 # -x;; - : int = -1073741824 But this is as specified for modular ints. No surprise here ... Regards -- Markus