""" Clase híbrida para números decimales """ from hybrid_base import HybridCalcType import re class HybridDec(HybridCalcType): """Clase híbrida para números decimales""" def __new__(cls, value_input): """Crear objeto SymPy válido""" obj = HybridCalcType.__new__(cls) return obj def __init__(self, value_input): """Inicialización de Dec""" # Convertir input a entero if isinstance(value_input, str): value = int(value_input) else: value = int(value_input) # Llamar al constructor base super().__init__(value, str(value)) def __str__(self): """Representación string para display""" return str(self._value) def _sympystr(self, printer): """Representación SymPy string""" return str(self) @staticmethod def Helper(input_str): """Ayuda contextual para Dec""" if re.match(r"^\s*Dec\b", input_str, re.IGNORECASE): return 'Ej: Dec[42], Dec[100]\nFunciones: toHex(), toBin()' return None @staticmethod def PopupFunctionList(): """Lista de métodos sugeridos para autocompletado de Dec""" return [ ("toHex", "Convierte a hexadecimal"), ("toBin", "Convierte a binario"), ] def toHex(self): """Convierte a hexadecimal""" return f"0x{self._value:02x}" def toBin(self): """Convierte a binario""" return f"0b{self._value:08b}"