Skip to content

Bit-shifts in Z/(n) #7949

@sagetrac-spancratz

Description

@sagetrac-spancratz

Currently, some code for bit-shifts in Z/(n) looks like

    def __lshift__(IntegerMod_gmp self, int right):
        ...
        cdef IntegerMod_gmp x
        x = self._new_c()
        mpz_mul_2exp(x.value, self.value, right)
        mpz_fdiv_r(x.value, x.value, self.__modulus.sageInteger.value)
        return x

where the method mpz_mul_2exp expect an unsigned long. Negative values of right thus cause undesired integral promotion.

Component: basic arithmetic

Keywords: bit shift, integer mod ring

Author: Sebastian Pancratz

Reviewer: Tom Boothby

Merged: sage-4.3.2.alpha0

Issue created by migration from https://trac.sagemath.org/ticket/7949

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions