def __init__(self, operand: ModelExpr, width=None): # create the output format if width is None: output_format = SIntFormat.from_values([operand.format_.min_val, operand.format_.max_val]) else: output_format = SIntFormat(width=width) assert output_format.can_represent(operand.format_.min_val), \ f'The given signed integer width {width} cannot represent the operand min value {operand.format.min_val}.' assert output_format.can_represent(operand.format_.max_val), \ f'The given signed integer width {width} cannot represent the operand max value {operand.format.max_val}.' # call the super constructor super().__init__(operand=operand, output_format=output_format)
def __init__(self, operand: ModelExpr, width=None): # create the output format if width is None: # make sure we can handle this case assert isinstance(operand.format_.range_, Number), \ f'The SInt width has to be specified in this case because the operand range is symbolic. For reference, the operand range expression is {operand.format_.range_}.' # create the output format min_int_val = int(floor(-operand.format_.range_)) max_int_val = int(ceil(operand.format_.range_)) output_format = SIntFormat.from_values([min_int_val, max_int_val]) else: output_format = SIntFormat(width=width) # call the superconstructor super().__init__(operand=operand, output_format=output_format)