self.ftest('atan2(1, 1)', math.atan2(1, 1), math.pi/4)
self.ftest('atan2(1, 0)', math.atan2(1, 0), math.pi/2)
+ # math.atan2(0, x)
+ self.ftest('atan2(0., -inf)', math.atan2(0., NINF), math.pi)
+ self.ftest('atan2(0., -2.3)', math.atan2(0., -2.3), math.pi)
+ self.ftest('atan2(0., -0.)', math.atan2(0., -0.), math.pi)
+ self.assertEqual(math.atan2(0., 0.), 0.)
+ self.assertEqual(math.atan2(0., 2.3), 0.)
+ self.assertEqual(math.atan2(0., INF), 0.)
+ self.assert_(math.isnan(math.atan2(0., NAN)))
+ # math.atan2(-0, x)
+ self.ftest('atan2(-0., -inf)', math.atan2(-0., NINF), -math.pi)
+ self.ftest('atan2(-0., -2.3)', math.atan2(-0., -2.3), -math.pi)
+ self.ftest('atan2(-0., -0.)', math.atan2(-0., -0.), -math.pi)
+ self.assertEqual(math.atan2(-0., 0.), -0.)
+ self.assertEqual(math.atan2(-0., 2.3), -0.)
+ self.assertEqual(math.atan2(-0., INF), -0.)
+ self.assert_(math.isnan(math.atan2(-0., NAN)))
+ # math.atan2(INF, x)
+ self.ftest('atan2(inf, -inf)', math.atan2(INF, NINF), math.pi*3/4)
+ self.ftest('atan2(inf, -2.3)', math.atan2(INF, -2.3), math.pi/2)
+ self.ftest('atan2(inf, -0.)', math.atan2(INF, -0.0), math.pi/2)
+ self.ftest('atan2(inf, 0.)', math.atan2(INF, 0.0), math.pi/2)
+ self.ftest('atan2(inf, 2.3)', math.atan2(INF, 2.3), math.pi/2)
+ self.ftest('atan2(inf, inf)', math.atan2(INF, INF), math.pi/4)
+ self.assert_(math.isnan(math.atan2(INF, NAN)))
+ # math.atan2(NINF, x)
+ self.ftest('atan2(-inf, -inf)', math.atan2(NINF, NINF), -math.pi*3/4)
+ self.ftest('atan2(-inf, -2.3)', math.atan2(NINF, -2.3), -math.pi/2)
+ self.ftest('atan2(-inf, -0.)', math.atan2(NINF, -0.0), -math.pi/2)
+ self.ftest('atan2(-inf, 0.)', math.atan2(NINF, 0.0), -math.pi/2)
+ self.ftest('atan2(-inf, 2.3)', math.atan2(NINF, 2.3), -math.pi/2)
+ self.ftest('atan2(-inf, inf)', math.atan2(NINF, INF), -math.pi/4)
+ self.assert_(math.isnan(math.atan2(NINF, NAN)))
+ # math.atan2(+finite, x)
+ self.ftest('atan2(2.3, -inf)', math.atan2(2.3, NINF), math.pi)
+ self.ftest('atan2(2.3, -0.)', math.atan2(2.3, -0.), math.pi/2)
+ self.ftest('atan2(2.3, 0.)', math.atan2(2.3, 0.), math.pi/2)
+ self.assertEqual(math.atan2(2.3, INF), 0.)
+ self.assert_(math.isnan(math.atan2(2.3, NAN)))
+ # math.atan2(-finite, x)
+ self.ftest('atan2(-2.3, -inf)', math.atan2(-2.3, NINF), -math.pi)
+ self.ftest('atan2(-2.3, -0.)', math.atan2(-2.3, -0.), -math.pi/2)
+ self.ftest('atan2(-2.3, 0.)', math.atan2(-2.3, 0.), -math.pi/2)
+ self.assertEqual(math.atan2(-2.3, INF), -0.)
+ self.assert_(math.isnan(math.atan2(-2.3, NAN)))
+ # math.atan2(NAN, x)
+ self.assert_(math.isnan(math.atan2(NAN, NINF)))
+ self.assert_(math.isnan(math.atan2(NAN, -2.3)))
+ self.assert_(math.isnan(math.atan2(NAN, -0.)))
+ self.assert_(math.isnan(math.atan2(NAN, 0.)))
+ self.assert_(math.isnan(math.atan2(NAN, 2.3)))
+ self.assert_(math.isnan(math.atan2(NAN, INF)))
+ self.assert_(math.isnan(math.atan2(NAN, NAN)))
+
def testCeil(self):
self.assertRaises(TypeError, math.ceil)
self.assertEquals(int, type(math.ceil(0.5)))
self.ftest('tanh(inf)', math.tanh(INF), 1)
self.ftest('tanh(-inf)', math.tanh(NINF), -1)
self.assert_(math.isnan(math.tanh(NAN)))
+ # check that tanh(-0.) == -0. on IEEE 754 systems
+ if float.__getformat__("double").startswith("IEEE"):
+ self.assertEqual(math.tanh(-0.), -0.)
+ self.assertEqual(math.copysign(1., math.tanh(-0.)),
+ math.copysign(1., -0.))
def test_trunc(self):
self.assertEqual(math.trunc(1), 1)
return result;
}
+/*
+ wrapper for atan2 that deals directly with special cases before
+ delegating to the platform libm for the remaining cases. This
+ is necessary to get consistent behaviour across platforms.
+ Windows, FreeBSD and alpha Tru64 are amongst platforms that don't
+ always follow C99.
+*/
+
+static double
+m_atan2(double y, double x)
+{
+ if (Py_IS_NAN(x) || Py_IS_NAN(y))
+ return Py_NAN;
+ if (Py_IS_INFINITY(y)) {
+ if (Py_IS_INFINITY(x)) {
+ if (copysign(1., x) == 1.)
+ /* atan2(+-inf, +inf) == +-pi/4 */
+ return copysign(0.25*Py_MATH_PI, y);
+ else
+ /* atan2(+-inf, -inf) == +-pi*3/4 */
+ return copysign(0.75*Py_MATH_PI, y);
+ }
+ /* atan2(+-inf, x) == +-pi/2 for finite x */
+ return copysign(0.5*Py_MATH_PI, y);
+ }
+ if (Py_IS_INFINITY(x) || y == 0.) {
+ if (copysign(1., x) == 1.)
+ /* atan2(+-y, +inf) = atan2(+-0, +x) = +-0. */
+ return copysign(0., y);
+ else
+ /* atan2(+-y, -inf) = atan2(+-0., -x) = +-pi. */
+ return copysign(Py_MATH_PI, y);
+ }
+ return atan2(y, x);
+}
+
/*
math_1 is used to wrap a libm function f that takes a double
arguments and returns a double.
"asinh(x)\n\nReturn the hyperbolic arc sine (measured in radians) of x.")
FUNC1(atan, atan, 0,
"atan(x)\n\nReturn the arc tangent (measured in radians) of x.")
-FUNC2(atan2, atan2,
+FUNC2(atan2, m_atan2,
"atan2(y, x)\n\nReturn the arc tangent (measured in radians) of y/x.\n"
"Unlike atan(y/x), the signs of both x and y are considered.")
FUNC1(atanh, atanh, 0,