[MLton] IntInf implementation questions

Matthew Fluet fluet@cs.cornell.edu
Mon, 6 Feb 2006 21:58:38 -0500 (EST)


> As  to  why fill() in IntInf.c requires at least 2 limbs, my guess looking at
> my old code is that it was (is?) to make sure that you  can  always  fit  any
> 32-bit  int in it.  I remember one had to be a bit cautious because of things
> that were small but whose negation were not.

O.k.

> Re quot and rem, I remember trying to use the mpn stuff (instead of  the  mpz
> things)   when  ever  possible  because  they  didn't  do  as  many  internal
> allocations.  If  you  look  at  atleast  the  old  (GMP  2.0.2)  source  for
> mpz_tdiv_[qr],  they  do pretty much the same as IntInf_quot/rem do, and they
> have all kinds of conditions under which they allocate.  You have to be  sure
> that  these  routines  do  NOT  allocate, or else you will end up with things
> pointing in the malloc heap instead of the MLton one.

That's a good reason.  I guess I'll try browsing the GMP source a little. 
I don't think it is that bad if GMP does some internal mallocs/frees, but 
certainly we want the final answer to go in the buffer we've allocated. 
I've not seen any problems using the mpz_tdiv_{q,r}, but I haven't really 
stress tested it.