A unary minus operator was applied to an unsigned type - conversion from 64 Bit to 32 Bit

Vincent Lefevre vincent at vinc17.net
Wed Sep 4 15:06:15 CEST 2024


On 2024-09-04 12:31:08 +0200, marco.bodrato at tutanota.com wrote:
> But an "Error" is worst than a "Warning" isn't it?

Note that in my initial reply in the MPFR mailing-list, I only saw
the warning (the messages were only in German and also obfuscated
by HTML markup and characters encoded as HTML entities).

> And the ERROR "A unary minus operator was applied to an unsigned type" is triggered by the following lines:
> mp_limb_t
> mpn_neg (mp_ptr __gmp_rp, mp_srcptr __gmp_up, mp_size_t __gmp_n)
> {
> [...]
>   *__gmp_rp = (- *__gmp_up) & GMP_NUMB_MASK;
> [...]
> }
> 
> To negate an mpn (an unsigned type), the relevant mp_limb_t (an unsigned type) is negated.
> How can we write this more clearly than this way?

Concerning this one, I agree that there is nothing wrong in the
GMP code and probably no better way to write it, as the goal is
precisely to negate an unsigned integer modulo 2^width, which is
exactly what the unary minus operator is for when applied on an
unsigned integer (similar to the other arithmetic operators).
There is nothing hidden by the code.

-- 
Vincent Lefèvre <vincent at vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)


More information about the gmp-bugs mailing list