All Downloads are FREE. Search and download functionalities are using the official Maven repository.

Lib.Krakatau.ssa.ssa_ops.truncate.py Maven / Gradle / Ivy

There is a newer version: 1.1
Show newest version
from .base import BaseOp
from ..constraints import IntConstraint
from . import bitwise_util

class Truncate(BaseOp):
    def __init__(self, parent, arg, signed, width):
        super(Truncate, self).__init__(parent, [arg])

        self.signed, self.width = signed, width
        self.rval = parent.makeVariable(arg.type, origin=self)

    def propagateConstraints(self, x):
        #get range of target type
        w = self.width
        intw = x.width
        assert(w < intw)
        M = 1<>1

            parts = [(i-M if i>=HM else i) for i in (x.min, x.max)]
            if x.min <= HM-1 <= x.max:
                parts.append(HM-1)            
            if x.min <= HM <= x.max:
                parts.append(-HM)

            assert(-HM <= min(parts) <= max(parts) <= HM-1)
            return IntConstraint.range(intw, min(parts), max(parts)), None, None
        else:
            return x, None, None




© 2015 - 2025 Weber Informatics LLC | Privacy Policy