Bugs or features?
Carlos Carreras
carreras at die.upm.es
Mon Feb 18 16:39:15 CET 2008
In the C standard, the behaviour of right shift of negative
numbers is
undefined. But in practice, almost every compiler defines it as
rounding towards -oo. The one exception I am aware of is Cray's
compilers for their vector systems. (They shift the numbers
logically
always, which is not very helpful.)
I am inclined to changing gmpxx.h to make it follow the common
behaviour, although that is not formally standardized.
What do people think? I am mainly interested in the opinion of
people
that actually use gmpxx.h.
(The change is trivial, just change the t to an f in
mpz_tdiv_q_2exp
in gmpxx.h.)
The term arithmetic shift does not mean shifts are arithmetic
operations. I'd rather keep shifts (even if arithmetic) as bitwise
operations emulating 2's complement (i.e. >> implemented as
floor(a/2^c)).
I program in C++ and use shifts also on floating-point types, and
combine native and gmp types in the algorithms. If the question refers
to operator>>= (I don't remember the original post), I prefer functions
(rather than operators) to multiply and divide by powers of two, so I
can define them also for the native types and use the same function for
all types. This way, I can specify types as template arguments and use
the same code for all types. So far, the compiler doesn't let me define
operator>> for double...
Carlos
More information about the gmp-discuss
mailing list