Browse thread
[Caml-list] Int overflow in literals
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | skaller <skaller@o...> |
| Subject: | Re: [Caml-list] Int overflow in literals |
On Mon, 2003-11-03 at 03:23, Brian Hurt wrote: > On 3 Nov 2003, skaller wrote: > > > On Fri, 2003-10-31 at 08:14, Oleg Trott wrote: > > > On Thursday 30 October 2003 03:05 pm, Issac Trotts wrote: > > > > > > > > Or, better yet, use Big_int: > > > > Felix does that, and i'm very happy with the idea. > > Constant folding is done in "infinite" precision. > > The check for size, if done, would occur in the backend > > code generator .. not the parser. > > > > This is a bad idea. I'd like the constant folding to be done in the word > length that the code will be executed in- this way, there is no difference > between code that is executed at run time and code that is executed at > compile time. > The results will be the same, so its a good idea :-) The Felix types 'int', 'long' etc have the same sizes as the corresponding C types. But the semantics are NOT the same. Bitwise operations are not permitted, and the result is undefined on overflow. The Felix type 'int32' on the other hand is required to be two's complement 32 bit, and allows overflow as in C. Bitwise operations are not allowed. The type 'uint32' allows bitwise operations. The constant folder respects these semantics. Actually only int type is folded .. and if the result would overflow at run time then the behaviour of the program is undefined, and so the well defined result of constant folding is correct, since it is an element of the set 'undefined' of all possible results :-) ------------------- 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