Feat: to_be_token decorator and force token to be Integer when it's
possible
This commit is contained in:
@@ -123,10 +123,13 @@ class MOnumber(Atom):
|
||||
"""
|
||||
if isinstance(value, Atom) and isinstance(value.value, (int, Decimal, float)):
|
||||
Atom.__init__(self, value.value)
|
||||
elif isinstance(value, (int, Decimal)):
|
||||
elif isinstance(value, (float, Decimal)):
|
||||
if int(value) == value:
|
||||
Atom.__init__(self, int(value))
|
||||
else:
|
||||
Atom.__init__(self, Decimal(value))
|
||||
elif isinstance(value, int):
|
||||
Atom.__init__(self, value)
|
||||
elif isinstance(value, float):
|
||||
Atom.__init__(self, Decimal(value))
|
||||
else:
|
||||
try:
|
||||
float(value)
|
||||
@@ -165,7 +168,7 @@ class MOnumber(Atom):
|
||||
>>> MOnumber(-3).__tex__
|
||||
'- 3'
|
||||
"""
|
||||
if self.value > 0:
|
||||
if self.value >= 0:
|
||||
return str(self.value)
|
||||
|
||||
return f"- {abs(self.value)}"
|
||||
|
Reference in New Issue
Block a user