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-09 (02:03)
From: skaller <skaller@u...>
Subject: Re: [Caml-list] if (n:int) < 0 then (-n) > 0 is FALSE
On Fri, 2006-12-08 at 13:37 -0500, Brian Hurt wrote:
> Mattias Engdegård wrote:
> > > I wouldn't call it a bug. It looks like modulo arithmetic to me.
> > >     
> > 
> > Let's not make a virtue of necessity. The type "int" was likely designed
> > with the intent to provide a type that could be used for actual integers
> > in a variety of circumstances, while giving good performance. The modulo
> > semantics is rarely useful (especially the 30-bit signed variety) but
> > is the price paid for reasonable performance with a simple implementation.
> >   
> Actually, the modulo behavior comes out of how the CPU designers made
> the CPUs work decades ago.  It was very easy for them to just drop all
> those extra bits (or not even compute them).  And, of course, now that
> behavior is cast in stone...

More precisely I think: CPU's have always preserved the information
in flags. The culprit here, as usual, is the C programming language.

John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: