Implementation of mp*_sgn()

Marc Glisse marc.glisse at inria.fr
Fri Nov 4 18:13:38 CET 2011


On Fri, 4 Nov 2011, Roberto Bagnara wrote:

> /* Allow faster testing for negative, zero, and positive.  */
> #define mpz_sgn(Z) ((Z)->_mp_size < 0 ? -1 : (Z)->_mp_size > 0)
> #define mpf_sgn(F) ((F)->_mp_size < 0 ? -1 : (F)->_mp_size > 0)
> #define mpq_sgn(Q) ((Q)->_mp_num._mp_size < 0 ? -1 : (Q)->_mp_num._mp_size > 
> 0)
>
> These macros possibly evaluate their arguments twice.

The documentation omits the "possibly":
"This function is actually implemented as a macro. It evaluates its 
argument multiple times."

;-)

> Would you accept a patch that substitutes them with inline functions?

(I can't speak for Torbjorn)

I don't see much wrong with making it an inline function (note that in 
that case we need to instantiate and export it in libgmp). I doubt anyone 
relies on the fact that it is a macro.

I am a bit surprised that it matters at all...

Why just those 3 and not all the other macros: mpz_odd, mpz_cmp_ui, etc?

-- 
Marc Glisse


More information about the gmp-discuss mailing list