Пример #1
0
 def test_11_c(self):
     """TestRepCodeTo68Cython.test_11_c(): to68() -1e40 is min Cython."""
     #        print()
     #        print('-1e40 = 0x{:08X} {:s}'.format(cRepCode.to68(-1e40), self.splitBits68(cRepCode.to68(-1e40))))
     #        print('  Min = 0x{:08X} {:g}'.format(cRepCode.to68(RepCode.minValue(68)), RepCode.minValue(68)))
     self.assertEqual(cRepCode.to68(-1e40),
                      cRepCode.to68(RepCode.minValue(68)))
Пример #2
0
 def test_time_00(self):
     """TestRepCodeTo68Time.test_time_00(): tests conversion of 1e6 of same word - Cython code."""
     i = 0
     num = 1e6
     tS = time.clock()
     while i < num:
         cRepCode.to68(153.0)
         i += 1
     self.writeTimeToStdErr(tS, 68, num)
Пример #3
0
 def test_time_10(self):
     """TestRepCodeTo68Time.test_time_10(): tests conversion of 1e5 random words - Cython code."""
     i = 0
     num = 1e5
     tS = time.clock()
     myMin, myMax = RepCode.minMaxValue(68)
     while i < num:
         val = myMin + random.random() * (myMax - myMin)
         cRepCode.to68(val)
         i += 1
     self.writeTimeToStdErr(tS, 68, num)
Пример #4
0
 def test_10_c(self):
     """TestRepCodeTo68Cython.test_10_c(): to68() <3.50325e-46 is zero Cython."""
     v = 3.50325e-46
     #        print()
     #        print('1e-40 = 0x{:08X} {:s} {:g}'.format(
     #            cRepCode.to68(v),
     #            self.splitBits68(cRepCode.to68(v)),
     #            cRepCode.from68(cRepCode.to68(v))),
     #        )
     self.assertEqual(0x00000001, cRepCode.to68(v))
     # Now reduce v slightly and we should see zero
     self.assertEqual(cRepCode.to68(0.99 * v), cRepCode.to68(0.0))
Пример #5
0
 def test_04(self):
     """TestRepCodeTo68LowExponent.test_04(): Special exponent tests, full range."""
     for e in range(-150, 128, 1):
         rcWord = pRepCode.to68(math.ldexp(0.5, e))
         self.assertEqual((0.5, e), math.frexp(pRepCode.from68(rcWord)))
     for e in range(-150, 128, 1):
         rcWord = cRepCode.to68(math.ldexp(0.5, e))
         self.assertEqual((0.5, e), math.frexp(cRepCode.from68(rcWord)))
     for e in range(-150, 128, 1):
         rcWord = RepCode.to68(math.ldexp(0.5, e))
         self.assertEqual((0.5, e), math.frexp(RepCode.from68(rcWord)))
Пример #6
0
 def test_02_c(self):
     """TestRepCodeTo68Cython.test_02_c(): to68(-153.0) -> 0xBBB38000 Cython."""
     v = -153.0
     #        e = cRepCode.to68(v)
     #        print()
     #        print('1e-40 = 0x{:08X} {:s} {:g}'.format(
     #            e,
     #            self.splitBits68(cRepCode.to68(v)),
     #            cRepCode.from68(cRepCode.to68(v))),
     #        )
     self.assertEqual(cRepCode.to68(v), 0xBBB38000)
Пример #7
0
 def test_time_02(self):
     """TestRepCodeTo68Time.test_time_02(): 1e6 same word  Cython time c.f. Python:"""
     i = 0
     num = 1e6
     tS = time.clock()
     while i < num:
         cRepCode.to68(153.0)
         i += 1
     tE_C = time.clock() - tS
     sys.stderr.write(' Cython: %.3f rate %8.0f words/S' %
                      (tE_C, num / tE_C))
     i = 0
     tS = time.clock()
     while i < num:
         pRepCode.to68(153.0)
         i += 1
     tE_P = time.clock() - tS
     sys.stderr.write(' Python: %.3f rate %8.f words/S' %
                      (tE_P, num / tE_P))
     sys.stderr.write(' %.1f%% (x%.1f) ' % ((100.0 *
                                             (tE_C / tE_P)), tE_P / tE_C))
Пример #8
0
    def test_03(self):
        """TestRepCodeTo68LowExponent.test_03(): Special exponent tests."""
        #        print()
        for e in (-151, -150, -129, -128, 0):
            rcWord = pRepCode.to68(math.ldexp(0.5, e))
#            print(
#                  'pRepCode.to68(math.ldexp(0.5, {:4d}))'.format(e),
#                  '0x{:08x}->{:s}'.format(rcWord, math.frexp(pRepCode.from68(rcWord)))
#            )
#print()
        for e in (-151, -150, -129, -128, 0):
            rcWord = cRepCode.to68(math.ldexp(0.5, e))
Пример #9
0
 def test_05(self):
     """TestRepCodeTo68LowExponent.test_02(): to68() exponent <-150 made to zero."""
     self.assertEqual(0x40000000, pRepCode.to68(math.ldexp(0.5, -151)))
     self.assertEqual(0x40000000, cRepCode.to68(math.ldexp(0.5, -151)))
     self.assertEqual(0x40000000, RepCode.to68(math.ldexp(0.5, -151)))
Пример #10
0
 def test_10(self):
     """TestRepCodeTo68PyCy.test_10(): to68() -999.25 -> 0xBA831800"""
     self.assertEqual('{:b}'.format(pRepCode.to68(-999.25)),
                      '{:b}'.format(cRepCode.to68(-999.25)))
     self.assertEqual(pRepCode.to68(-999.25), cRepCode.to68(-999.25))
     self.assertEqual(RepCode.to68(-999.25), 0xBA831800)
Пример #11
0
 def test_12_c(self):
     """TestRepCodeTo68Cython.test_12_c(): to68() +1e40 is max Cython."""
     self.assertEqual(cRepCode.to68(+1e40),
                      cRepCode.to68(RepCode.maxValue(68)))
Пример #12
0
 def test_03_c(self):
     """TestRepCodeTo68Cython.test_03__(): to68(0.0) -> 0x40000000 Cython."""
     self.assertEqual(cRepCode.to68(0.0), 0x40000000)
Пример #13
0
 def test_01_c(self):
     """TestRepCodeTo68Cython.test_01_c(): to68(153.0) -> 0x444C8000 Cython ."""
     self.assertEqual(cRepCode.to68(153.0), 0x444C8000)
Пример #14
0
 def time_cRepCode_to(self):
     cRepCode.to68(153.0)
Пример #15
0
 def test_to_minus_153_c(self):
     """TestRepCodeToFrom68CPython.test_02_c(): to68(0xBBB38000) -> -153.0 CPython."""
     result = cRepCode.to68(-153.0)
     self.assertEqual(result, 0xBBB38000)