Exemplo n.º 1
0
 def testConversion(self):
     return
     for mul in [-2, -1, -.8, -.3, 0.1, 0.3, 0.331, 0.6, 0.9, 1, 1.2]:
         for d in [
                 0.0001, 0.1234, 0.5, 0.51, 0.52, 0.53, 0.7, 1, 1.1, 1.2,
                 1.22, 2.9, 0
         ]:
             val = mul * d
             print(val)
             print(Adau145x.decimal_repr(val))
             self.assertAlmostEqual(
                 val, Adau145x.decimal_val(Adau145x.decimal_repr(val)), 5)
Exemplo n.º 2
0
    def testValues(self):
        # Known good representations (calculated in SigmaStudio)
        known_good = {
            0x80000000: -128,
            0xFF000000: -1,
            0: 0,
            0x40000000: 64,
            0x1000000: 1,
            0x10000: 0.00390625,
        }

        for b in known_good:
            f = known_good[b]
            self.assertEqual(b, Adau145x.decimal_repr(f),
                             "float -> int failed for {}/{}".format(b, f))
            self.assertEqual(f, Adau145x.decimal_val(b),
                             "int -> float failed for {}/{}".format(b, f))