Fix/tweak numbers implementation
Round fixed point decimals in initialiser to match Python behaviour Add pretty printing for Python
This commit is contained in:
parent
15dd93cf24
commit
8a304aedcf
@ -28,7 +28,7 @@ class Fixed:
|
|||||||
if isinstance(val, Fixed):
|
if isinstance(val, Fixed):
|
||||||
self.impl = val.impl
|
self.impl = val.impl
|
||||||
else:
|
else:
|
||||||
self.impl = Big(val)
|
self.impl = Big(val).round(Big.DP)
|
||||||
|
|
||||||
def pp(self, dp):
|
def pp(self, dp):
|
||||||
"""Pretty print to specified number of decimal places"""
|
"""Pretty print to specified number of decimal places"""
|
||||||
|
@ -34,6 +34,8 @@ class Fixed:
|
|||||||
else:
|
else:
|
||||||
self.impl = Decimal(val).quantize(_quantize_exp)
|
self.impl = Decimal(val).quantize(_quantize_exp)
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return '<Fixed {}>'.format(str(self.impl))
|
||||||
def pp(self, dp):
|
def pp(self, dp):
|
||||||
"""Pretty print to specified number of decimal places"""
|
"""Pretty print to specified number of decimal places"""
|
||||||
return format(self.impl, '.{}f'.format(dp))
|
return format(self.impl, '.{}f'.format(dp))
|
||||||
|
@ -27,6 +27,8 @@ class Native:
|
|||||||
else:
|
else:
|
||||||
self.impl = float(val)
|
self.impl = float(val)
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return '<Native {}>'.format(str(self.impl))
|
||||||
def pp(self, dp):
|
def pp(self, dp):
|
||||||
"""Pretty print to specified number of decimal places"""
|
"""Pretty print to specified number of decimal places"""
|
||||||
return format(self.impl, '.{}f'.format(dp))
|
return format(self.impl, '.{}f'.format(dp))
|
||||||
|
@ -28,6 +28,8 @@ class Rational:
|
|||||||
else:
|
else:
|
||||||
self.impl = Fraction(val)
|
self.impl = Fraction(val)
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return '<Rational {}>'.format(str(self.impl))
|
||||||
def pp(self, dp):
|
def pp(self, dp):
|
||||||
"""
|
"""
|
||||||
Pretty print to specified number of decimal places
|
Pretty print to specified number of decimal places
|
||||||
|
Reference in New Issue
Block a user