> Alastair Reid <[EMAIL PROTECTED]> writes: 
> > 
> ...
> > 
> > However, your mail does remind me that we have {Word,Int}32 and
> > friends for use when we do want to calculate modulo 2^32 - converting
> > to them should certainly not give exceptions.  This is what Sigbjorn
> > (I think it was he who raised the issue) should have been using if he
> > was relying on not getting exceptions.
> > 
> 
> Indeed, I was using Int32. However, since Hugs' implementation of Int32
> is built on top of Int the behaviour is the same.


Aha, a bug in the bug report! :-)

Now that we're talking about Int32, it seems quite obvious that
Integer->Int32 should work modulo 2^32 and not raise an exception and
that whoever wrote the existing Integer->Int32 code should be slapped
with a damp leek and forced to go rock climbing.

In the hope of halving my sentence, here's what ought to be a working
version:

  integerToInt32 x = word32ToInt32 (integerToWord32 (x `mod` maxWordPlus1))
  maxWordPlus1 = 2^32

Coding this in C would not be much more efficient - Hugs'
representation of Integers (essentially a list of digits) pretty much
forces the mod operation and the word32ToInt32 is a no-op.

Now where did that leek go?


Alastair

Reply via email to