Exemplo n.º 1
0
 def test_divide_int_fixed_point_infinite_precision(self):
     a = 10
     b = FixedPoint(3, QFormat(8, 8))
     c = a / b
     self.assertIsInstance(c, FixedPoint)
     self.assertEqual(c, FixedPoint(3.33203125))
Exemplo n.º 2
0
 def test_divide_complex_fixed_point(self):
     a = 12 + 6j
     b = FixedPoint(3, QFormat(5, 11))
     c = a / b
     self.assertIsInstance(c, complex)
     self.assertEqual(c, (4 + 2j))
Exemplo n.º 3
0
 def test_divide_fixed_point_complex(self):
     a = FixedPoint(14.625, QFormat(5, 11))
     b = 3 - 1j
     c = a / b
     self.assertIsInstance(c, complex)
     self.assertEqual(c, (4.3875 + 1.4625j))
Exemplo n.º 4
0
 def test_divide_int_fixed_point(self):
     a = 12
     b = FixedPoint(4, QFormat(8, 8))
     c = a / b
     self.assertIsInstance(c, FixedPoint)
     self.assertEqual(c, FixedPoint(3))
Exemplo n.º 5
0
 def test_multiply_complex_fixed_point(self):
     a = 3 - 2j
     b = FixedPoint(14.625, QFormat(5, 11))
     c = a * b
     self.assertIsInstance(c, complex)
     self.assertEqual(c, 43.875 - 29.25j)
Exemplo n.º 6
0
 def test_divide_fixed_point_int_infinite_precision(self):
     a = FixedPoint(10, QFormat(8, 8))
     b = 3
     c = a / b
     self.assertIsInstance(c, FixedPoint)
     self.assertEqual(c, FixedPoint(3.33349609375))
Exemplo n.º 7
0
 def test_multiply_int_fixed_point(self):
     a = 7
     b = FixedPoint(12.1875, QFormat(8, 8))
     c = a * b
     self.assertIsInstance(c, FixedPoint)
     self.assertEqual(c, FixedPoint(85.3125))
Exemplo n.º 8
0
 def test_multiply_fraction_fixed_point(self):
     a = Fraction(1, 3)
     b = FixedPoint(12.1875, QFormat(8, 8))
     c = a * b
     self.assertIsInstance(c, Fraction)
     self.assertEqual(c, Fraction(65, 16))
Exemplo n.º 9
0
 def test_multiply_fixed_point_fixed_point_fractional(self):
     a = FixedPoint(3.125, QFormat(8, 8))
     b = FixedPoint(12.1875, QFormat(8, 8))
     c = a * b
     self.assertIsInstance(c, FixedPoint)
     self.assertEqual(c, FixedPoint(38.0859375))
Exemplo n.º 10
0
 def test_multiply_float_fixed_point(self):
     a = 12.1875
     b = FixedPoint(3.125, QFormat(8, 8))
     c = a * b
     self.assertIsInstance(c, float)
     self.assertEqual(c, 38.0859375)
Exemplo n.º 11
0
 def test_multiply_fixed_point_fixed_point_integers(self):
     a = FixedPoint(3, QFormat(5, 3))
     b = FixedPoint(5, QFormat(6, 2))
     c = a * b
     self.assertIsInstance(c, FixedPoint)
     self.assertEqual(c, FixedPoint(15))
Exemplo n.º 12
0
 def test_pow_fixed_point_complex(self):
     a = FixedPoint(2.5, QFormat(5, 11))
     b = 3 - 2j
     c = a**b
     self.assertIsInstance(c, complex)
     self.assertEqual(c, (-4.043832497129643 - 15.092648665332344j))
Exemplo n.º 13
0
 def test_mod_complex_fixed_point(self):
     a = 12 + 6j
     b = FixedPoint(3, QFormat(5, 11))
     with self.assertRaises(TypeError):
         c = a % b
Exemplo n.º 14
0
 def test_mod_int_fixed_point(self):
     a = 12
     b = FixedPoint(5, QFormat(8, 8))
     c = a % b
     self.assertIsInstance(c, FixedPoint)
     self.assertEqual(c, FixedPoint(2))
Exemplo n.º 15
0
 def test_mod_fixed_point_complex(self):
     a = FixedPoint(14.625, QFormat(5, 11))
     b = 3 - 1j
     with self.assertRaises(TypeError):
         c = a % b