def test_readme(self): vec = dulp(1., [1. + 2.**-52, 1. + 2.**-50]) self.assertEqual(vec.shape, (2, )) self.assertEqual(list(vec), [1., 4.]) self.assertEqual( dulp(float32((1 + 5**0.5) / 2), float32(1.6180339887)), 0.) with self.assertRaises(TypeError): dulp(-0., float32(0.))
def test_broadcastf(self): vec = dulp(.5, [.7] * 2) mat = dulp(.5, .5 * numpy.ones((1, 2, 3))) self.assertEqual(vec.shape, (2, )) self.assertEqual(mat.shape, (1, 2, 3)) self.assertEqual(vec[0], dulp(.5, .7)) with self.assertRaises(ValueError): dulp(vec, mat)
def test_type(self): self.assertIs(dulp(.5, .7).dtype.type, float64) self.assertIsInstance(dulp([.5], [.7]), numpy.ndarray) self.assertIs(dulp(float32(.5), float32(.7)).dtype.type, float64) self.assertIsInstance(dulp([float32(.5)], [float32(.7)]), numpy.ndarray) with self.assertRaises(TypeError): dulp(float32(1), float64(0.5)) with self.assertRaises(TypeError): dulp(1j, 1j) with self.assertRaises(TypeError): dulp(0, 5e-324)
def test_bits(self): self.assertEqual(bits(0.), 0.) self.assertEqual(bits(1.), 1.) self.assertEqual(bits(7), 3.) self.assertLess(bits(8), 4.) self.assertGreater(bits(8), 3.) self.assertLess(bits(dulp(-inf, inf)), 64.)
def test_incrementf(self): self.assertEqual(dulp(float32(1. - 2**-24), float32(1.)), 1.) self.assertEqual(dulp(float32(1.5), float32(1.5 + 2**-23)), 1.) self.assertEqual(dulp(float32(0.), float32(1e-45)), 1.) self.assertEqual(dulp(float32(1e-45), float32(3e-45)), 1.) self.assertEqual(dulp(f32min - float32(1e-45), f32min), 1.) self.assertEqual(dulp(f32max, float32(inf)), 1.) self.assertEqual(dulp(-float32(0.), float32(0.)), 1.)
def test_increment(self): self.assertEqual(dulp(1. - 2**-53, 1.), 1.) self.assertEqual(dulp(1.5, 1.5 + 2**-52), 1.) self.assertEqual(dulp(0., 5e-324), 1.) self.assertEqual(dulp(5e-324, 1e-323), 1.) self.assertEqual(dulp(f64min - 5e-324, f64min), 1.) self.assertEqual(dulp(f64max, inf), 1.) self.assertEqual(dulp(-0., 0.), 1.)
def test_nanf(self): self.assertEqual(dulp(float32(nan), float32(nan)), 0.)
def test_asymf(self): self.assertEqual(dulp(float32(.5), float32(.7)), -dulp(float32(.7), float32(.5))) self.assertEqual(dulp(float32(.5), float32(.7)), -dulp(-float32(.5), -float32(.7)))
def test_jumpf(self): self.assertEqual(dulp(float32(1.), float32(1.5)), 2**22.)
def test_nan(self): self.assertEqual(dulp(nan, nan), 0.)
def test_asym(self): self.assertEqual(dulp(.5, .7), -dulp(.7, .5)) self.assertEqual(dulp(.5, .7), -dulp(-.5, -.7))
def test_jump(self): self.assertEqual(dulp(1., 1.5), 2**51.)
def test_absolute(self): self.assertEqual(bits(dulp(.5, .7)), bits(dulp(.7, .5)))