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
if (n:int) < 0 then (-n) > 0 is FALSE
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2006-12-07 (19:43)
From: Mattias_Engdegård <mattias@v...>
Subject: Re: [Caml-list] if (n:int) < 0 then (-n) > 0 is FALSE
>It's not a bug -- you're relying on 32bit ints when OCaml has only
>31bit ints (on 32-bit arch). In C (for example), if you use a plain
>int (I believe it'll default to signed), you get the exact same
>behaviour when the number overflows 2^31.

(Signed overflow is not legal in C (undefined behaviour), and a decent
compiler will warn this can be detected statically.)

Of course it is a bug - a design bug, since the behaviour is intended
and documented, but still a bug. But getting numbers, even integers,
right in every respect is hard, and involves trade-offs between
performance, correctness and convenience.

I would love to have a fast unboxed integer type that automatically
overflows to bignum, but it would be a tad slower than the current "int".