52 lines
1.3 KiB
Python
52 lines
1.3 KiB
Python
"""
|
|
Clase híbrida para números decimales
|
|
"""
|
|
from hybrid_base import HybridCalcType
|
|
|
|
|
|
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"""
|
|
return """
|
|
Formato Dec:
|
|
- Número entero: 42
|
|
|
|
Conversiones:
|
|
- 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}" |