From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id AAA30508; Fri, 31 Oct 2003 00:44:35 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id AAA30497 for ; Fri, 31 Oct 2003 00:44:33 +0100 (MET) Received: from pecan.cc.columbia.edu (pecan.cc.columbia.edu [128.59.59.178]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h9UNiE101009 for ; Fri, 31 Oct 2003 00:44:14 +0100 (MET) Received: from tw304h3.cpmc.columbia.edu (tw304h3.cpmc.columbia.edu [156.111.84.180]) (user=ot14 mech=LOGIN bits=0) by pecan.cc.columbia.edu (8.12.10/8.12.10) with ESMTP id h9UNhuwF009156 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NOT); Thu, 30 Oct 2003 18:43:56 -0500 (EST) From: Oleg Trott To: fvdp@decis.be, OCaml Mailing List Subject: Re: [Caml-list] Int overflow in literals Date: Thu, 30 Oct 2003 18:43:35 -0500 User-Agent: KMail/1.5.4 References: <1067522012.5880.6.camel@qrnik> <20031030200519.GA19324@ucdavis.edu> <3FA18458.6F8F30D5@decis.be> In-Reply-To: <3FA18458.6F8F30D5@decis.be> MIME-Version: 1.0 Content-Type: text/plain; charset="windows-1251" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200310301843.35157.oleg_trott@columbia.edu> X-No-Spam-Score: Local X-Scanned-By: MIMEDefang 2.35 X-Loop: caml-list@inria.fr X-Spam: no; 0.00; oleg:01 oleg:01 caml-list:01 plancke:01 issac:01 trotts:01 marcin:01 'qrczak':01 kowalczyk:01 issac:01 compiler:01 ocaml:01 ocaml:01 imho:01 int:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Thursday 30 October 2003 04:36 pm, Frederic van der Plancke wrote: > Issac Trotts wrote: > > On Thu, Oct 30, 2003 at 02:53:32PM +0100, Marcin 'Qrczak' Kowalczyk wrote: > > > I understand that int overflow is not checked on arithmetic for > > > efficiency reasons, but IMHO it would be better if it was checked > > > at least in literals. When someone writes 10000000000, he certainly > > > does not mean -737418240. > > > > If you want to be sure that the number is correctly stored, you can use > > Int64: > > > > Int64.of_string "10000000000" > > > > Issac > > That was not my problem. My problem was to be able to read a list of > integers from a file and be warned in case of overflow. And to be able to > rely on int_of_string for that purpose. I got hit... of course now I know, > but other innocent programmers may get hit in the future as well. (Not to > speak of the not-so-innocent people who wrote this nice OCaml compiler ;-) ... and this is what Issac (and myself) suggested (by implication): let int_of_string s = Big_int.int_of_big_int (Big_int.big_int_of_string s) We addressed your specific problem. But I agree with you that it would be nice to have the safe behavior in OCaml by default (at least for parsing, where performance wouldn't be affected) -- Oleg Trott ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners