Example #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))
Example #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))
Example #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))
Example #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))
Example #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)
Example #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))
Example #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))
Example #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))
Example #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))
Example #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)
Example #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))
Example #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))
Example #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
Example #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))
Example #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