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 (20:02)
From: Brian Hurt <bhurt@j...>
Subject: Re: [Caml-list] if (n:int) < 0 then (-n) > 0 is FALSE
Mattias Engdegård wrote:

>>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".

I find it interesting that the languages I know use fixed-size integers 
(Ocaml, C, C++, Java, C#, Fortran, Pascal) are at or near the top of the 
great computer language shootout, while the languages I know don't 
(Perl, Python) are near the bottom.  Not that I'm saying that this is 
the case, it's just an interesting dichotomy.