bug-gmp
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

GMP compiled under MacOS/C++ wrap


From: Hans Aberg
Subject: GMP compiled under MacOS/C++ wrap
Date: Mon, 23 Apr 2001 16:15:48 +0200

[Followups, please cc me, as I am not on this list.]

I compiled GMP <ftp://ftp.gnu.org/pub/gnu/gmp/gmp-3.0.tar.gz> generic under
pre-MacOS X with Metrowerks CodeWarrior Pro 5 C/C++ compiler, using the
32-bit gmp-mparam.h header. (Note that the Mac G4 CPU is 128 bit, and there
appears to be no header for that.)

I started on a C++ wrap, classes gmp::integer, gmp::rational, gmp::floating
that expand to the GMP C functions. If you are interested, please let me
know. I don not plan to write all GMP functions into that wrap, but it
would not be difficult to do so. (More info below.)

Some bugs:

- mpq_swap, mpf_swap are mentioned in the manual, but are not in the gmp.h
header.

- mpz_inp_binary
  mpz_out_binary
  mpf_ceil
  mpf_floor
  mpf_trunc
are in the gmp.h header, but have no definition.

- When including gmp.h under C++, I ran into the problem that gmp.h defines
the keyword "inline" to empty. Somehow you have to make sure that "inline"
is defined as normal when the header is finished reading, otherwise it
produces hard to understand link errors.

- In gmp.h, I noticed the lines:
  /* Really use `defined (__STDC__)' here; we want it to be true for Sun C */
  #if defined (__STDC__) || defined (__cplusplus)
Note that under C++ (cf. C.1.9:1 in the C++ standard), __STDC__
implementation defined.

Now a suggest:

- When making C++ classes, it would be natural to put in a reference count,
in order to avoid unnecessary copying. However, dynamic allocations are
slow, so making a ref-count on __mpz_struct would cause a double memory
allocation, which would be slow. Therefore, one should I arrive at the idea
to put it in the limbs themselves, that is, something like:

typedef struct
{
  mp_limb_t *_mp_all;           /* Pointer to all.  */
} __mpz_struct;

#define _mp_count _mp_all[0]
#define _mp_alloc _mp_all[1]
#define _mp_size  _mp_all[2]
#define _mp_d     _mp_all + 3

But the library would have been to be rewritten, at the points one
allocates and deletes _mp_d, as it now is _mp_all that should be allocated.
(And _mp_size now becomes unsigned, it would have been  to be explicitly
coerced.)

But at least under C++, a ref-count seems reasonable, because arithmetic
operators can return gmp::integer, gmp::rational, and gmp::floating values
without calling a new dynamic allocation.

  Hans Aberg





reply via email to

[Prev in Thread] Current Thread [Next in Thread]