Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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: 2003-10-31 (17:51)
From: Oleg Trott <oleg_trott@c...>
Subject: Re: [Caml-list] Int overflow in literals
On Friday 31 October 2003 11:42 am, Xavier Leroy 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.
> > It caused confusion in a class when someone was interactively testing
> > a function with larger and larger inputs.
> This is a very good suggestion.  There are several ways to go about this:
> - The lexer emits a warning in case of overflow, and proceeds with
>   the value modulo the size of the type.
> - The lexer emits an error on overflow.
> - The int_of_string functions raise an exception on overflow.
> Based on the comments posted so far on this list, and on a quick
> discussion with colleagues, I'm inclined toward the third approach
> (int_of_string fails in case of overflow).  Does anyone know of a use
> scenario where this new behavior of int_of_string would be a problem?

How much do you think the performance of "typical programs" would be affected
(in percent) if +, - and * were also made to raise an exception on overflow?

Oleg Trott <>

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: