Version française
Home     About     Download     Resources     Contact us    
Browse thread
2147483648l < 2147483647l
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: David Allsopp <dra-news@m...>
Subject: RE: [Caml-list] 2147483648l < 2147483647l
Goswin von Brederlow wrote:
> "David Allsopp" <dra-news@metastack.com> 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