From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id D5886BBAF for ; Tue, 19 Jan 2010 19:28:44 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AvsBALqIVUtRZ90xkWdsb2JhbACbfwEBAQEJCwoHEwO7boQzBA X-IronPort-AV: E=Sophos;i="4.49,305,1262559600"; d="scan'208";a="54318851" Received: from mtaout03-winn.ispmail.ntl.com ([81.103.221.49]) by mail4-smtp-sop.national.inria.fr with ESMTP; 19 Jan 2010 19:28:44 +0100 Received: from aamtaout03-winn.ispmail.ntl.com ([81.103.221.35]) by mtaout03-winn.ispmail.ntl.com (InterMail vM.7.08.04.00 201-2186-134-20080326) with ESMTP id <20100119182843.VAIN17277.mtaout03-winn.ispmail.ntl.com@aamtaout03-winn.ispmail.ntl.com> for ; Tue, 19 Jan 2010 18:28:43 +0000 Received: from romulus.metastack.com ([81.102.132.77]) by aamtaout03-winn.ispmail.ntl.com (InterMail vG.2.02.00.01 201-2161-120-102-20060912) with ESMTP id <20100119182843.RJEH2093.aamtaout03-winn.ispmail.ntl.com@romulus.metastack.com> for ; Tue, 19 Jan 2010 18:28:43 +0000 Received: from Tenor ([172.16.0.8]) (authenticated bits=0) by romulus.metastack.com (8.14.2/8.14.2) with ESMTP id o0JISdRF002052 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO) for ; Tue, 19 Jan 2010 18:28:40 GMT From: "David Allsopp" To: "'OCaml List'" References: <4B4337A0.8000603@fiit.stuba.sk> <000101ca8e0a$aa006450$fe012cf0$@romulus.metastack.com> <87ska2gelk.fsf@frosties.localdomain> In-Reply-To: <87ska2gelk.fsf@frosties.localdomain> Subject: RE: [Caml-list] 2147483648l < 2147483647l Date: Tue, 19 Jan 2010 18:28:32 -0000 Message-ID: <00ff01ca9935$3539b050$9fad10f0$@romulus.metastack.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQLDro19qzdMCtSmfnfCXcGpCw8+8AIkYaIOA29GKfQBSBfOig== Content-Language: en-gb Organization: MetaStack Solutions Ltd. X-Scanned-By: MIMEDefang 2.65 on 81.102.132.77 X-Cloudmark-Analysis: v=1.1 cv=1ggfb5FlKZQUfF3vzm9UBYZ2uTfLsbs/8dSljwg5+mE= c=1 sm=0 a=SGJpDYsEAAAA:8 a=OHAyWOh76-C6UKkMTLMA:9 a=HxFwXLZMAOtENK-CF1tmnDO_AXcA:4 a=dTth3pfvbawA:10 a=HpAAvcLHHh0Zw7uRqdWCyQ==:117 X-Spam: no; 0.00; bool:01 bug:01 ocaml:01 bug:01 compiler:01 syntax:01 wrote:01 wrote:01 exception:01 ints:01 caml-list:01 arithmetic:01 int:01 int:01 writes:01 Goswin von Brederlow wrote: > "David Allsopp" writes: > > > Matej Kosik wrote: > >> I am sorry, I have a stupid question. > >> I would like to ask if this: > >> > >> # 2147483648l < 2147483647l;; > >> - : bool = true > > > > The bug is in fact: > > > > # 2147483648l;; > > - : int32 = -2147483648l > > > > and given that behaviour, the above result makes sense! But... > > Isn't that documented properly? I think in the docs I saw at least that > ocaml will silently overflow ints. Arithmetic operations are allowed to overflow silently but at no point do you end up with an illegal constant which is the bug here. i.e. Int32.add 2147483647l 1l correctly evaluates to -2147483648l but -2147483648l is a valid int32. The evaluation of a constant by the compiler in your ML source is supposed to follow the same rules as Int32.of_string (which would raise an exception if given "-2147483648l") hence 2147483648l which is not a valid int32 should be a "syntax" error. David