Пример #1
0
 def __new__(cls,
             precision=None,
             emin=None,
             emax=None,
             subnormalize=None,
             rounding=None):
     if precision is not None and \
             not (PRECISION_MIN <= precision <= PRECISION_MAX):
         raise ValueError("Precision p should satisfy %d <= p <= %d." %
                          (PRECISION_MIN, PRECISION_MAX))
     if emin is not None and not EMIN_MIN <= emin <= EMIN_MAX:
         raise ValueError("exponent bound emin should satisfy "
                          "%d <= emin <= %d" % (EMIN_MIN, EMIN_MAX))
     if emax is not None and not EMAX_MIN <= emax <= EMAX_MAX:
         raise ValueError("exponent bound emax should satisfy "
                          "%d <= emax <= %d" % (EMAX_MIN, EMAX_MAX))
     if rounding is not None:
         rounding = RoundingMode(rounding)
     if subnormalize is not None and subnormalize not in [False, True]:
         raise ValueError("subnormalize should be either False or True")
     self = object.__new__(cls)
     self._precision = precision
     self._emin = emin
     self._emax = emax
     self._subnormalize = subnormalize
     self._rounding = rounding
     return self
Пример #2
0
 def test_invalid_rounding_mode(self):
     with self.assertRaises(ValueError):
         RoundingMode(-1)
Пример #3
0
 def test_rounding_mode_from_rounding_mode(self):
     rm = RoundingMode(ROUND_TOWARD_POSITIVE)
     self.assertEqual(rm, ROUND_TOWARD_POSITIVE)
     self.assertIsInstance(rm, RoundingMode)
Пример #4
0
 def test_rounding_mode_from_int(self):
     rm = RoundingMode(mpfr.MPFR_RNDN)
     self.assertEqual(rm, ROUND_TIES_TO_EVEN)
     self.assertIsInstance(rm, RoundingMode)