# Collection of code snippets by Arne Vajhøj 
# (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
from decimal import *

def get_scale(d):
    return -d.as_tuple().exponent

def dump(a, op, b, res):
    print('%s (%d) %s %s (%d)= %s (%d)' % (a, get_scale(a), op, b, get_scale(b), res, get_scale(res)))

a = Decimal('4.2')
b = Decimal('0.8')
c = Decimal('5')
d = Decimal('2.1')
e = Decimal('6.2')
f = Decimal('3.1')
g = Decimal('-4.2')
res = a + b
dump(a, '+', b, res)
res = a - b
dump(a, '-', b, res)
res = a * c
dump(a, '*', c, res)
res = a / d
dump(a, '/', d, res)
res = d / a
dump(d, '/', a, res)
res = f / e
dump(f, '/', e, res)
res = d / g
dump(d, '/', g, res)
