22# Python test set -- math module
33# XXXX Should not do tests around zero only
44
5- from test .support import run_unittest , verbose # , requires_IEEE_754 # TODO: RUSTPYTHON, commented due to import error
5+ from test .support import run_unittest , verbose , requires_IEEE_754
66from test import support
77import unittest
88import itertools
@@ -442,7 +442,6 @@ def testCopysign(self):
442442 # similarly, copysign(2., NAN) could be 2. or -2.
443443 self .assertEqual (abs (math .copysign (2. , NAN )), 2. )
444444
445- @unittest .skip ('TODO: RUSTPYTHON' )
446445 def testCos (self ):
447446 self .assertRaises (TypeError , math .cos )
448447 self .ftest ('cos(-pi/2)' , math .cos (- math .pi / 2 ), 0 , abs_tol = math .ulp (1 ))
@@ -1475,7 +1474,6 @@ def testTan(self):
14751474 self .assertRaises (ValueError , math .tan , NINF )
14761475 self .assertTrue (math .isnan (math .tan (NAN )))
14771476
1478- @unittest .skip ('TODO: RUSTPYTHON' )
14791477 def testTanh (self ):
14801478 self .assertRaises (TypeError , math .tanh )
14811479 self .ftest ('tanh(0)' , math .tanh (0 ), 0 )
@@ -1948,75 +1946,76 @@ def testComb(self):
19481946 self .assertIs (type (comb (IntSubclass (5 ), IntSubclass (k ))), int )
19491947 self .assertIs (type (comb (MyIndexable (5 ), MyIndexable (k ))), int )
19501948
1951- # TODO: RUSTPYTHON
1952- # @requires_IEEE_754
1953- # def test_nextafter(self):
1954- # # around 2^52 and 2^63
1955- # self.assertEqual(math.nextafter(4503599627370496.0, -INF),
1956- # 4503599627370495.5)
1957- # self.assertEqual(math.nextafter(4503599627370496.0, INF),
1958- # 4503599627370497.0)
1959- # self.assertEqual(math.nextafter(9223372036854775808.0, 0.0),
1960- # 9223372036854774784.0)
1961- # self.assertEqual(math.nextafter(-9223372036854775808.0, 0.0),
1962- # -9223372036854774784.0)
1963-
1964- # # around 1.0
1965- # self.assertEqual(math.nextafter(1.0, -INF),
1966- # float.fromhex('0x1.fffffffffffffp-1'))
1967- # self.assertEqual(math.nextafter(1.0, INF),
1968- # float.fromhex('0x1.0000000000001p+0'))
1969-
1970- # # x == y: y is returned
1971- # self.assertEqual(math.nextafter(2.0, 2.0), 2.0)
1972- # self.assertEqualSign(math.nextafter(-0.0, +0.0), +0.0)
1973- # self.assertEqualSign(math.nextafter(+0.0, -0.0), -0.0)
1974-
1975- # # around 0.0
1976- # smallest_subnormal = sys.float_info.min * sys.float_info.epsilon
1977- # self.assertEqual(math.nextafter(+0.0, INF), smallest_subnormal)
1978- # self.assertEqual(math.nextafter(-0.0, INF), smallest_subnormal)
1979- # self.assertEqual(math.nextafter(+0.0, -INF), -smallest_subnormal)
1980- # self.assertEqual(math.nextafter(-0.0, -INF), -smallest_subnormal)
1981- # self.assertEqualSign(math.nextafter(smallest_subnormal, +0.0), +0.0)
1982- # self.assertEqualSign(math.nextafter(-smallest_subnormal, +0.0), -0.0)
1983- # self.assertEqualSign(math.nextafter(smallest_subnormal, -0.0), +0.0)
1984- # self.assertEqualSign(math.nextafter(-smallest_subnormal, -0.0), -0.0)
1985-
1986- # # around infinity
1987- # largest_normal = sys.float_info.max
1988- # self.assertEqual(math.nextafter(INF, 0.0), largest_normal)
1989- # self.assertEqual(math.nextafter(-INF, 0.0), -largest_normal)
1990- # self.assertEqual(math.nextafter(largest_normal, INF), INF)
1991- # self.assertEqual(math.nextafter(-largest_normal, -INF), -INF)
1992-
1993- # # NaN
1994- # self.assertIsNaN(math.nextafter(NAN, 1.0))
1995- # self.assertIsNaN(math.nextafter(1.0, NAN))
1996- # self.assertIsNaN(math.nextafter(NAN, NAN))
1997-
1998- # @requires_IEEE_754
1999- # def test_ulp(self):
2000- # self.assertEqual(math.ulp(1.0), sys.float_info.epsilon)
2001- # # use int ** int rather than float ** int to not rely on pow() accuracy
2002- # self.assertEqual(math.ulp(2 ** 52), 1.0)
2003- # self.assertEqual(math.ulp(2 ** 53), 2.0)
2004- # self.assertEqual(math.ulp(2 ** 64), 4096.0)
2005-
2006- # # min and max
2007- # self.assertEqual(math.ulp(0.0),
2008- # sys.float_info.min * sys.float_info.epsilon)
2009- # self.assertEqual(math.ulp(FLOAT_MAX),
2010- # FLOAT_MAX - math.nextafter(FLOAT_MAX, -INF))
2011-
2012- # # special cases
2013- # self.assertEqual(math.ulp(INF), INF)
2014- # self.assertIsNaN(math.ulp(math.nan))
2015-
2016- # # negative number: ulp(-x) == ulp(x)
2017- # for x in (0.0, 1.0, 2 ** 52, 2 ** 64, INF):
2018- # with self.subTest(x=x):
2019- # self.assertEqual(math.ulp(-x), math.ulp(x))
1949+ @requires_IEEE_754
1950+ def test_nextafter (self ):
1951+ # around 2^52 and 2^63
1952+ self .assertEqual (math .nextafter (4503599627370496.0 , - INF ),
1953+ 4503599627370495.5 )
1954+ self .assertEqual (math .nextafter (4503599627370496.0 , INF ),
1955+ 4503599627370497.0 )
1956+ self .assertEqual (math .nextafter (9223372036854775808.0 , 0.0 ),
1957+ 9223372036854774784.0 )
1958+ self .assertEqual (math .nextafter (- 9223372036854775808.0 , 0.0 ),
1959+ - 9223372036854774784.0 )
1960+
1961+ # around 1.0
1962+ self .assertEqual (math .nextafter (1.0 , - INF ),
1963+ float .fromhex ('0x1.fffffffffffffp-1' ))
1964+ self .assertEqual (math .nextafter (1.0 , INF ),
1965+ float .fromhex ('0x1.0000000000001p+0' ))
1966+
1967+ # x == y: y is returned
1968+ self .assertEqual (math .nextafter (2.0 , 2.0 ), 2.0 )
1969+ self .assertEqualSign (math .nextafter (- 0.0 , + 0.0 ), + 0.0 )
1970+ self .assertEqualSign (math .nextafter (+ 0.0 , - 0.0 ), - 0.0 )
1971+
1972+ # around 0.0
1973+ # TODO: RUSTPYTHON
1974+ # smallest_subnormal = sys.float_info.min * sys.float_info.epsilon
1975+ # self.assertEqual(math.nextafter(+0.0, INF), smallest_subnormal)
1976+ # self.assertEqual(math.nextafter(-0.0, INF), smallest_subnormal)
1977+ # self.assertEqual(math.nextafter(+0.0, -INF), -smallest_subnormal)
1978+ # self.assertEqual(math.nextafter(-0.0, -INF), -smallest_subnormal)
1979+ # self.assertEqualSign(math.nextafter(smallest_subnormal, +0.0), +0.0)
1980+ # self.assertEqualSign(math.nextafter(-smallest_subnormal, +0.0), -0.0)
1981+ # self.assertEqualSign(math.nextafter(smallest_subnormal, -0.0), +0.0)
1982+ # self.assertEqualSign(math.nextafter(-smallest_subnormal, -0.0), -0.0)
1983+
1984+ # around infinity
1985+ largest_normal = sys .float_info .max
1986+ self .assertEqual (math .nextafter (INF , 0.0 ), largest_normal )
1987+ self .assertEqual (math .nextafter (- INF , 0.0 ), - largest_normal )
1988+ self .assertEqual (math .nextafter (largest_normal , INF ), INF )
1989+ self .assertEqual (math .nextafter (- largest_normal , - INF ), - INF )
1990+
1991+ # NaN
1992+ self .assertIsNaN (math .nextafter (NAN , 1.0 ))
1993+ self .assertIsNaN (math .nextafter (1.0 , NAN ))
1994+ self .assertIsNaN (math .nextafter (NAN , NAN ))
1995+
1996+ @requires_IEEE_754
1997+ def test_ulp (self ):
1998+ self .assertEqual (math .ulp (1.0 ), sys .float_info .epsilon )
1999+ # use int ** int rather than float ** int to not rely on pow() accuracy
2000+ self .assertEqual (math .ulp (2 ** 52 ), 1.0 )
2001+ self .assertEqual (math .ulp (2 ** 53 ), 2.0 )
2002+ self .assertEqual (math .ulp (2 ** 64 ), 4096.0 )
2003+
2004+ # min and max
2005+ # TODO: RUSTPYTHON
2006+ # self.assertEqual(math.ulp(0.0),
2007+ # sys.float_info.min * sys.float_info.epsilon)
2008+ self .assertEqual (math .ulp (FLOAT_MAX ),
2009+ FLOAT_MAX - math .nextafter (FLOAT_MAX , - INF ))
2010+
2011+ # special cases
2012+ self .assertEqual (math .ulp (INF ), INF )
2013+ self .assertIsNaN (math .ulp (math .nan ))
2014+
2015+ # negative number: ulp(-x) == ulp(x)
2016+ for x in (0.0 , 1.0 , 2 ** 52 , 2 ** 64 , INF ):
2017+ with self .subTest (x = x ):
2018+ self .assertEqual (math .ulp (- x ), math .ulp (x ))
20202019
20212020 @unittest .skip ('TODO: RUSTPYTHON' )
20222021 def test_issue39871 (self ):
@@ -2183,4 +2182,4 @@ def test_main():
21832182 run_unittest (suite )
21842183
21852184if __name__ == '__main__' :
2186- test_main ()
2185+ test_main ()
0 commit comments