(self, exp, man, neg)
return self
Normalise from shifted mantissa, exp, sign.
Normalise from shifted mantissa, exp, sign.
Normalise from shifted mantissa exp sign .
def _normalise(self, exp, man, neg):
        """Normalise from shifted mantissa, exp, sign."""
        # zero denormalised mantissa -> make zero
        if man == 0 or exp <= 0:
            self._buffer[:] = b'\0' * self.size
            return self
        # shift left if subnormal
        while man < (self._den_mask-1):
            exp -= 1
            man <<= 1
        # round to nearest; halves to even (Gaussian rounding)
        round_up = (man & 0xff > 0x80) or (man & 0xff == 0x80 and man & 0x100 == 0x100)
        man = (man & self._carrymask) + 0x100 * round_up
        if man >= self._den_upper:
            exp += 1
            man >>= 1
        # pack into byte representation
        struct.pack_into(
            self._intformat, self._buffer, 0, (man>>8) & (self._mask if neg else self._posmask)
        )
        if self._check_limits(exp, neg):
            self._buffer[-1:] = int2byte(exp)
        return self
def _normalise ( self , exp , man , neg ) : # zero denormalised mantissa -> make zero if man == 0 or exp <= 0 : self . _buffer [ : ] = b'\0' * self . size return self # shift left if subnormal while man < ( self . _den_mask - 1 ) : exp -= 1 man <<= 1 # round to nearest; halves to even (Gaussian rounding) round_up = ( man & 0xff > 0x80 ) or ( man & 0xff == 0x80 and man & 0x100 == 0x100 ) man = ( man & self . _carrymask ) + 0x100 * round_up if man >= self . _den_upper : exp += 1 man >>= 1 # pack into byte representation struct . pack_into ( self . _intformat , self . _buffer , 0 , ( man >> 8 ) & ( self . _mask if neg else self . _posmask ) ) if self . _check_limits ( exp , neg ) : self . _buffer [ - 1 : ] = int2byte ( exp ) return self