diff --git a/html/index.html b/html/index.html index ecea932..fcb5f47 100644 --- a/html/index.html +++ b/html/index.html @@ -39,7 +39,7 @@ diff --git a/pyRCV2/method/base_stv.py b/pyRCV2/method/base_stv.py index 1e69150..ecb066d 100644 --- a/pyRCV2/method/base_stv.py +++ b/pyRCV2/method/base_stv.py @@ -458,9 +458,9 @@ class BaseUIGSTVCounter(BaseSTVCounter): # Credit votes for candidate, cand_votes in next_preferences.items(): __pragma__('opov') - self.candidates[candidate].transfers += Num(cand_votes.__floor__().pp(0)) + self.candidates[candidate].transfers += cand_votes.to_num() __pragma__('noopov') __pragma__('opov') - self.exhausted.transfers += Num(next_exhausted.__floor__().pp(0)) + self.exhausted.transfers += next_exhausted.to_num() __pragma__('noopov') diff --git a/pyRCV2/numbers/rational_js.py b/pyRCV2/numbers/rational_js.py index b7db956..cacb27a 100644 --- a/pyRCV2/numbers/rational_js.py +++ b/pyRCV2/numbers/rational_js.py @@ -23,9 +23,21 @@ class Rational: self.impl = bigRat(val) def pp(self, dp): - """Pretty print to specified number of decimal places""" + """ + Pretty print to specified number of decimal places + This will fail for numbers which cannot be represented as a JavaScript number + """ return self.impl.valueOf().toFixed(dp) + def to_num(self): + """ + Convert to an instance of Num + """ + from pyRCV2.numbers import Num + __pragma__('opov') + return Num(self.impl.numerator.toString()) / Num(self.impl.denominator.toString()) + __pragma__('noopov') + def __add__(self, other): return Rational(self.impl.add(other.impl)) def __sub__(self, other): diff --git a/pyRCV2/numbers/rational_py.py b/pyRCV2/numbers/rational_py.py index 6d4a56e..9f23c81 100644 --- a/pyRCV2/numbers/rational_py.py +++ b/pyRCV2/numbers/rational_py.py @@ -26,9 +26,18 @@ class Rational: self.impl = Fraction(val) 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)) + def to_num(self): + """ + Convert to an instance of Num + """ + from pyRCV2.numbers import Num + return Num(self.impl.numerator) / Num(self.impl.denominator) + def __add__(self, other): return Rational(self.impl + other.impl) def __sub__(self, other):