Bitwise logic gmpxx.h problems

Torbjorn Granlund tg at swox.com
Thu Jul 31 13:13:07 CEST 2008


Marc Glisse <marc.glisse at normalesup.org> writes:

  The goal of the function is to do something like p=-expr. The current 
  version evaluates expr and puts the result in temp. It then does p=-temp. 
  The one I suggested evaluates expr and puts the result in p. It then does 
  p=-p. It basically saves a copy from temp to p in some cases.
  
I nderstand that much, but not what keys to press in order to make
that happen in C++.  :-)

  > The mpz->_mp_alloc field is "aware" of the allocation.  Or what do you
  > mean?
  
  _mp_alloc is aware of what allocation size is requested from malloc. If 
  malloc happens to allocate more (because I replaced the standard malloc 
  by my own that allocates only even numbers of limbs), _mp_alloc does not 
  know it. This means that replacing malloc/realloc/free is not such a nice 
  way to specify an allocation policy.
  
In C, there is only one portable mechanism for allocating memory, and
its interface is rather primitive.  Getting back the actual allocation
would be a minor improvement of it.

  > OK, I'll use the terse C++'y std::numeric_limits<double>::max_exponent.
  
  I am not sure it is as portable as DBL_MAX_EXP from <cfloat>, but we'll 
  see. It's easy to switch anyway if one causes trouble.
  
I indeed got some failures.  I'll try DBL_MAX_EXP next.

Programming for C++ is real science, not plain computer science; you
need to take an experimental approach as not even the C++ experts can
tell what works and what does not work, or whether certain constructs
are valid or invalid.  :-)

-- 
Torbjörn


More information about the gmp-bugs mailing list