Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Int overflow in literals
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Oleg Trott <oleg_trott@c...>
Subject: Re: [Caml-list] Int overflow in literals
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 <oleg_trott@columbia.edu>

-------------------
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