Add functionality for the use of decimal type
I was a contributor to the previous repo over on bitbucket, I will see if I can find my code for this. I remember running into an precision issue and therefor wanted a to have the decimal type as an option.
I have not tested yet (mabe if I have some time next weekend I'll add that) but it should probably work already with decimals.
from unum import as_unum
from decimal import Decimal
from unum.units import m
a = as_unum(Decimal(2), m)
this is the issue I am trying to fix with the imperial units:
ounce = oz_t = new_unit("oz t", 31.1034768*g, "Troy ounce")
pound = lb_t = new_unit("lb t", 12*oz_t, "Troy Pound")
pennyweight = pwt = pwt = new_unit("pwt", oz_t/20, "Troy Pennyweight")
grain = gr_t = new_unit("gr t", pwt/24, "Troy grain")
Even when defined as: ounce = oz_t = new_unit("oz t", dec(31.1034768)*g, "Troy ounce")
these test fail:
def test_ounce(self):
self.assertAlmostEqual(31.1034768, oz_t.cast_unit(g).number(),7) #float causes inacuracies
def test_ounce_dec(self):
self.assertEqual(dec("31.1034768"), as_unum(dec(1), oz_t).cast_unit(g).number()) # float causes inacuracies
def test_ounce_dec2(self):
self.assertEqual(dec("31.1034768"), oz_t.cast_unit(g).number()) # float causes inacuracies
would it be possible to set an option to use decimal type. defining all units with decimal, then if this option is disabled convert to float (losing the precision benefit in exchange for hardware arithmetic)