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-30 (17:59)
From: Frederic van der Plancke <fvdp@d...>
Subject: Re: [Caml-list] Int overflow in literals
Alex Baretta wrote:
> 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.
> >
> > It caused confusion in a class when someone was interactively testing
> > a function with larger and larger inputs.
> >
> I bet the official answer is "It's can't be done because native integers
> are 31 bits on 32 bit platforms, 63 bits on 64 bit platforms, so what is
> parser supposed to do? Especially in the case of the bytecode compiler."
> Although, I suppose something could be done in the toplevel.

I think int_of_string is the culprit and must change (last time I checked,
int_of_string "10000000000" returned -737418240).
(sorry if that's already been done in 3.07, I haven't tried it yet.)

There's not much execution time to gain by not letting it check the overflow,
and there's no easy way to write a "correct" safety wrapper for that function
(as it would have to accept arguments like "-0000000123456789", it
would be easier to rewrite it from scratch.)

Ditto for int_of_float (int_of_float 10000000000.0 = -737418240), even
though there the safety wrapper is easier to write (and the relative loss of
execution time would probably be greater.))

I think that understanding "language safety" as "never triggers access
violation" is a tad restrictive...


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