• Home
  • Raw
  • Download

Lines Matching +full:win32 +full:- +full:ia32

1 # Python test set -- math module
17 eps = 1E-05
20 NINF = float('-inf')
24 # detect evidence of double-rounding: fsum is not always correctly
40 """Convert a non-NaN float x to an integer, in such a way that
42 abs(ulps(x) - ulps(y)) gives the difference in ulps between two
48 Note: 0.0 and -0.0 are converted to 0 and -1, respectively.
61 # factorial(n) = factorial_odd_part(n) << (n - count_set_bits(n))
71 # We iterate downwards from i == n.bit_length() - 1 to i == 0. The inner
79 return 1 + count_set_bits(n & n - 1) if n else 0
86 numfactors = (stop - start) >> 1
104 return outer << (n - count_set_bits(n))
113 ulp_error = abs(to_ulps(expected) - to_ulps(got))
114 abs_error = abs(expected - got)
127 -- starts a comment
130 id fn arg -> expected [flag]*
133 with open(fname, encoding="utf-8") as fp:
136 if '--' in line:
137 line = line[:line.index('--')]
141 lhs, rhs = line.split('->')
153 Empty lines or lines starting with -- are ignored
156 with open(fname, encoding="utf-8") as fp:
159 if line.startswith('--') or not line.strip():
162 lhs, rhs = line.split('->')
181 non-finite floats, exact equality is demanded. Also, nan==nan
193 # Turn mixed float and int comparison (e.g. floor()) to all-float
245 non-finite floats, exact equality is demanded. Also, nan==nan
260 self.ftest('acos(-1)', math.acos(-1), math.pi)
266 self.assertRaises(ValueError, math.acos, -1 - eps)
274 self.assertRaises(ValueError, math.acosh, -1)
281 self.ftest('asin(-1)', math.asin(-1), -math.pi/2)
287 self.assertRaises(ValueError, math.asin, -1 - eps)
294 self.ftest('asinh(-1)', math.asinh(-1), -0.88137358701954305)
301 self.ftest('atan(-1)', math.atan(-1), -math.pi/4)
305 self.ftest('atan(-inf)', math.atan(NINF), -math.pi/2)
312 self.ftest('atanh(-0.5)', math.atanh(-0.5), -0.54930614433405489)
314 self.assertRaises(ValueError, math.atanh, -1)
321 self.ftest('atan2(-1, 0)', math.atan2(-1, 0), -math.pi/2)
322 self.ftest('atan2(-1, 1)', math.atan2(-1, 1), -math.pi/4)
328 self.ftest('atan2(0., -inf)', math.atan2(0., NINF), math.pi)
329 self.ftest('atan2(0., -2.3)', math.atan2(0., -2.3), math.pi)
330 self.ftest('atan2(0., -0.)', math.atan2(0., -0.), math.pi)
335 # math.atan2(-0, x)
336 self.ftest('atan2(-0., -inf)', math.atan2(-0., NINF), -math.pi)
337 self.ftest('atan2(-0., -2.3)', math.atan2(-0., -2.3), -math.pi)
338 self.ftest('atan2(-0., -0.)', math.atan2(-0., -0.), -math.pi)
339 self.assertEqual(math.atan2(-0., 0.), -0.)
340 self.assertEqual(math.atan2(-0., 2.3), -0.)
341 self.assertEqual(math.atan2(-0., INF), -0.)
342 self.assertTrue(math.isnan(math.atan2(-0., NAN)))
344 self.ftest('atan2(inf, -inf)', math.atan2(INF, NINF), math.pi*3/4)
345 self.ftest('atan2(inf, -2.3)', math.atan2(INF, -2.3), math.pi/2)
346 self.ftest('atan2(inf, -0.)', math.atan2(INF, -0.0), math.pi/2)
352 self.ftest('atan2(-inf, -inf)', math.atan2(NINF, NINF), -math.pi*3/4)
353 self.ftest('atan2(-inf, -2.3)', math.atan2(NINF, -2.3), -math.pi/2)
354 self.ftest('atan2(-inf, -0.)', math.atan2(NINF, -0.0), -math.pi/2)
355 self.ftest('atan2(-inf, 0.)', math.atan2(NINF, 0.0), -math.pi/2)
356 self.ftest('atan2(-inf, 2.3)', math.atan2(NINF, 2.3), -math.pi/2)
357 self.ftest('atan2(-inf, inf)', math.atan2(NINF, INF), -math.pi/4)
360 self.ftest('atan2(2.3, -inf)', math.atan2(2.3, NINF), math.pi)
361 self.ftest('atan2(2.3, -0.)', math.atan2(2.3, -0.), math.pi/2)
365 # math.atan2(-finite, x)
366 self.ftest('atan2(-2.3, -inf)', math.atan2(-2.3, NINF), -math.pi)
367 self.ftest('atan2(-2.3, -0.)', math.atan2(-2.3, -0.), -math.pi/2)
368 self.ftest('atan2(-2.3, 0.)', math.atan2(-2.3, 0.), -math.pi/2)
369 self.assertEqual(math.atan2(-2.3, INF), -0.)
370 self.assertTrue(math.isnan(math.atan2(-2.3, NAN)))
373 self.assertTrue(math.isnan(math.atan2(NAN, -2.3)))
374 self.assertTrue(math.isnan(math.atan2(NAN, -0.)))
386 self.ftest('cbrt(-0.0)', math.cbrt(-0.0), -0.0)
388 self.ftest('cbrt(-2.6)', math.cbrt(-2.6), -1.375068867074141)
390 self.ftest('cbrt(-1)', math.cbrt(-1), -1)
391 self.ftest('cbrt(-27)', math.cbrt(-27), -3)
402 self.assertEqual(math.ceil(-0.5), 0)
403 self.assertEqual(math.ceil(-1.0), -1)
404 self.assertEqual(math.ceil(-1.5), -1)
406 self.assertEqual(math.ceil(-0.0), 0)
433 self.assertEqual(math.copysign(1., -42), -1.0)
435 self.assertEqual(math.copysign(4., -0.), -4.0)
440 self.assertEqual(math.copysign(1., -0.), -1.)
442 self.assertEqual(math.copysign(INF, -0.), NINF)
444 self.assertEqual(math.copysign(NINF, -0.), NINF)
447 self.assertEqual(math.copysign(1., NINF), -1.)
460 # similarly, copysign(2., NAN) could be 2. or -2.
465 self.ftest('cos(-pi/2)', math.cos(-math.pi/2), 0, abs_tol=math.ulp(1))
468 self.ftest('cos(pi)', math.cos(math.pi), -1)
477 @unittest.skipIf(sys.platform == 'win32' and platform.machine() in ('ARM', 'ARM64'),
482 self.ftest('cosh(2)-2*cosh(1)**2', math.cosh(2)-2*math.cosh(1)**2, -1) # Thanks to Lambert
491 self.ftest('degrees(-pi/4)', math.degrees(-math.pi/4), -45.0)
496 self.ftest('exp(-1)', math.exp(-1), 1/math.e)
506 self.ftest('exp2(-1)', math.exp2(-1), 0.5)
517 self.ftest('fabs(-1)', math.fabs(-1), 1)
528 self.assertRaises(ValueError, math.factorial, -1)
529 self.assertRaises(ValueError, math.factorial, -10**100)
534 self.assertRaises(TypeError, math.factorial, -1.0)
535 self.assertRaises(TypeError, math.factorial, -1e100)
554 self.assertEqual(math.floor(-0.5), -1)
555 self.assertEqual(math.floor(-1.0), -1)
556 self.assertEqual(math.floor(-1.5), -2)
584 self.ftest('fmod(-10, 1)', math.fmod(-10, 1), -0.0)
585 self.ftest('fmod(-10, 0.5)', math.fmod(-10, 0.5), -0.0)
586 self.ftest('fmod(-10, 1.5)', math.fmod(-10, 1.5), -1.0)
595 self.assertEqual(math.fmod(-3.0, INF), -3.0)
597 self.assertEqual(math.fmod(-3.0, NINF), -3.0)
606 if abs(mant-emant) > eps or exp != eexp:
610 testfrexp('frexp(-1)', math.frexp(-1), (-0.5, 1))
624 # There's a known problem with IA32 floating-point that causes
636 etiny = float_info.min_exp - mant_dig
647 mant, exp = int(math.ldexp(mant, mant_dig)), exp - mant_dig
649 tmant <<= texp-exp
652 mant <<= exp-texp
656 # a little unsafe because str -> float conversion can't be
658 tail = max(len(bin(abs(tmant)))-2 - mant_dig, etiny - texp)
660 h = 1 << (tail-1)
661 tmant = tmant // (2*h) + bool(tmant & h and tmant & 3*h-1)
668 ([1e100, 1.0, -1e100, 1e-100, 1e50, -1.0, -1e50], 1e-100),
669 ([2.0**53, -0.5, -2.0**-54], 2.0**53-1.0),
670 ([2.0**53, 1.0, 2.0**-100], 2.0**53+2.0),
671 ([2.0**53+10.0, 1.0, 2.0**-100], 2.0**53+12.0),
672 ([2.0**53-4.0, 0.5, 2.0**-54], 2.0**53-3.0),
675 ([(-1.)**n/n for n in range(1, 1001)],
676 float.fromhex('-0x1.62a2af1bd3624p-1')),
677 ([1e16, 1., 1e-16], 10000000000000002.0),
678 ([1e16-2., 1.-2.**-53, -(1e16-2.), -(1.-2.**-53)], 0.0),
680 ([2.**n - 2.**(n+50) + 2.**(n+52) for n in range(-1074, 972, 2)] +
681 [-2.**1022],
688 [terms[i+1] - terms[i] for i in range(1000)] + [-terms[1000]],
689 -terms[0]
705 vals = [7, 1e100, -7, -1e100, -9e-20, 8e-20] * 10
708 v = gauss(0, random()) ** 7 - s
720 self.assertEqual(gcd(-1, 0), 1)
722 self.assertEqual(gcd(0, -1), 1)
724 self.assertEqual(gcd(7, -1), 1)
725 self.assertEqual(gcd(-23, 15), 1)
727 self.assertEqual(gcd(84, -120), 12)
739 self.assertEqual(gcd(-a, b), c)
740 self.assertEqual(gcd(b, -a), c)
741 self.assertEqual(gcd(a, -b), c)
742 self.assertEqual(gcd(-b, a), c)
743 self.assertEqual(gcd(-a, -b), c)
744 self.assertEqual(gcd(-b, -a), c)
748 self.assertEqual(gcd(-120), 120)
782 self.assertEqual(hypot(-10.5), 10.5) # Negative input
785 math.copysign(1.0, hypot(-0.0)) # Convert negative zero to positive zero
805 self.assertEqual(hypot(-10, INF), INF)
810 self.assertEqual(hypot(-INF, INF), INF)
811 self.assertEqual(hypot(-INF, -INF), INF)
812 self.assertEqual(hypot(10, -INF), INF)
904 self.assertEqual(dist((1.0, 2.0, 3.0), (4.0, 2.0, -1.0)), 5.0)
905 self.assertEqual(dist((1, 2, 3), (4, 2, -1)), 5.0)
911 p = tuple(random.uniform(-5, 5) for k in range(i))
912 q = tuple(random.uniform(-5, 5) for k in range(i))
915 sqrt(sum((px - qx) ** 2.0 for px, qx in zip(p, q)))
918 # Test non-tuple inputs
919 self.assertEqual(dist([1.0, 2.0, 3.0], [4.0, 2.0, -1.0]), 5.0)
920 self.assertEqual(dist(iter([1.0, 2.0, 3.0]), iter([4.0, 2.0, -1.0])), 5.0)
923 self.assertEqual(dist((14.0, 1.0), (2.0, -4.0)), 13.0)
924 self.assertEqual(dist((14, 1), (2, -4)), 13)
925 self.assertEqual(dist((D(14), D(1)), (D(2), D(-4))), D(13))
926 self.assertEqual(dist((F(14, 32), F(1, 32)), (F(2, 32), F(-4, 32))),
933 self.assertEqual(dist((13.25, 12.5, -3.25),
934 (13.25, 12.5, -3.25)),
936 self.assertEqual(dist((), ()), 0.0) # Zero-dimensional case
938 math.copysign(1.0, dist((-0.0,), (0.0,)))
941 math.copysign(1.0, dist((0.0,), (-0.0,)))
951 self.assertEqual(dist(T((1, 2, 3)), ((4, 2, -1))), 5.0)
979 self.assertEqual(dist((p,), (q,)), abs(p - q))
982 values = [NINF, -10.5, -0.0, 0.0, 10.5, INF, NAN]
985 diffs = [px - qx for px, qx in zip(p, q)]
1010 # gh-98897: Check for error handling does not leak memory
1018 + list(range(10**6 - 1000, 10**6 + 1000))
1019 + [2**e + i for e in range(60, 200) for i in range(-40, 40)]
1032 math.isqrt(-1)
1034 # Integer-like things
1055 math.isqrt(IntegerLike(-3))
1057 # Non-integer-like things
1060 100.0, -4.0,
1071 self.assertEqual(lcm(-1, 0), 0)
1073 self.assertEqual(lcm(0, -1), 0)
1075 self.assertEqual(lcm(7, -1), 7)
1076 self.assertEqual(lcm(-23, 15), 345)
1078 self.assertEqual(lcm(84, -120), 840)
1092 self.assertEqual(lcm(-a, b), d)
1093 self.assertEqual(lcm(b, -a), d)
1094 self.assertEqual(lcm(a, -b), d)
1095 self.assertEqual(lcm(-b, a), d)
1096 self.assertEqual(lcm(-a, -b), d)
1097 self.assertEqual(lcm(-b, -a), d)
1101 self.assertEqual(lcm(-120), 120)
1115 self.ftest('ldexp(1,-1)', math.ldexp(1,-1), 0.5)
1116 self.ftest('ldexp(-1,1)', math.ldexp(-1,1), -2)
1118 self.assertRaises(OverflowError, math.ldexp, -1., 1000000)
1119 self.assertEqual(math.ldexp(1., -1000000), 0.)
1120 self.assertEqual(math.ldexp(-1., -1000000), -0.)
1122 self.assertEqual(math.ldexp(NINF, -213), NINF)
1127 self.assertEqual(math.ldexp(INF, -n), INF)
1128 self.assertEqual(math.ldexp(NINF, -n), NINF)
1129 self.assertEqual(math.ldexp(1., -n), 0.)
1130 self.assertEqual(math.ldexp(-1., -n), -0.)
1131 self.assertEqual(math.ldexp(0., -n), 0.)
1132 self.assertEqual(math.ldexp(-0., -n), -0.)
1133 self.assertTrue(math.isnan(math.ldexp(NAN, -n)))
1136 self.assertRaises(OverflowError, math.ldexp, -1., n)
1138 self.assertEqual(math.ldexp(-0., n), -0.)
1145 self.ftest('log(1/e)', math.log(1/math.e), -1)
1153 self.assertRaises(ValueError, math.log, -1.5)
1154 self.assertRaises(ValueError, math.log, -10**1000)
1163 self.assertRaises(ValueError, math.log1p, -1)
1180 self.assertRaises(ValueError, math.log2, -1.5)
1189 actual = [math.log2(math.ldexp(1.0, n)) for n in range(-1074, 1024)]
1190 expected = [float(n) for n in range(-1074, 1024)]
1195 self.ftest('log10(0.1)', math.log10(0.1), -1)
1199 self.assertRaises(ValueError, math.log10, -1.5)
1200 self.assertRaises(ValueError, math.log10, -10**1000)
1210 if abs(v1-e1) > eps or abs(v2-e2):
1215 testmodf('modf(-1.5)', math.modf(-1.5), (-0.5, -1.0))
1218 self.assertEqual(math.modf(NINF), (-0.0, NINF))
1229 self.ftest('pow(2,-1)', math.pow(2,-1), 0.5)
1245 self.assertEqual(math.pow(0., -0.), 1.)
1246 self.assertRaises(ValueError, math.pow, 0., -2.)
1247 self.assertRaises(ValueError, math.pow, 0., -2.3)
1248 self.assertRaises(ValueError, math.pow, 0., -3.)
1258 self.assertEqual(math.pow(INF, -0.), 1.)
1259 self.assertEqual(math.pow(INF, -2.), 0.)
1260 self.assertEqual(math.pow(INF, -2.3), 0.)
1261 self.assertEqual(math.pow(INF, -3.), 0.)
1265 # pow(-0., x)
1266 self.assertEqual(math.pow(-0., INF), 0.)
1267 self.assertEqual(math.pow(-0., 3.), -0.)
1268 self.assertEqual(math.pow(-0., 2.3), 0.)
1269 self.assertEqual(math.pow(-0., 2.), 0.)
1270 self.assertEqual(math.pow(-0., 0.), 1.)
1271 self.assertEqual(math.pow(-0., -0.), 1.)
1272 self.assertRaises(ValueError, math.pow, -0., -2.)
1273 self.assertRaises(ValueError, math.pow, -0., -2.3)
1274 self.assertRaises(ValueError, math.pow, -0., -3.)
1275 self.assertEqual(math.pow(-0., NINF), INF)
1276 self.assertTrue(math.isnan(math.pow(-0., NAN)))
1284 self.assertEqual(math.pow(NINF, -0.), 1.)
1285 self.assertEqual(math.pow(NINF, -2.), 0.)
1286 self.assertEqual(math.pow(NINF, -2.3), 0.)
1287 self.assertEqual(math.pow(NINF, -3.), -0.)
1291 # pow(-1, x)
1292 self.assertEqual(math.pow(-1., INF), 1.)
1293 self.assertEqual(math.pow(-1., 3.), -1.)
1294 self.assertRaises(ValueError, math.pow, -1., 2.3)
1295 self.assertEqual(math.pow(-1., 2.), 1.)
1296 self.assertEqual(math.pow(-1., 0.), 1.)
1297 self.assertEqual(math.pow(-1., -0.), 1.)
1298 self.assertEqual(math.pow(-1., -2.), 1.)
1299 self.assertRaises(ValueError, math.pow, -1., -2.3)
1300 self.assertEqual(math.pow(-1., -3.), -1.)
1301 self.assertEqual(math.pow(-1., NINF), 1.)
1302 self.assertTrue(math.isnan(math.pow(-1., NAN)))
1310 self.assertEqual(math.pow(1., -0.), 1.)
1311 self.assertEqual(math.pow(1., -2.), 1.)
1312 self.assertEqual(math.pow(1., -2.3), 1.)
1313 self.assertEqual(math.pow(1., -3.), 1.)
1319 self.assertEqual(math.pow(-2.3, 0.), 1.)
1321 self.assertEqual(math.pow(2.3, -0.), 1.)
1322 self.assertEqual(math.pow(-2.3, -0.), 1.)
1323 self.assertEqual(math.pow(NAN, -0.), 1.)
1326 self.assertRaises(ValueError, math.pow, -1., 2.3)
1327 self.assertRaises(ValueError, math.pow, -15., -3.1)
1334 self.assertEqual(math.pow(-0.1, NINF), INF)
1335 self.assertEqual(math.pow(-0.9, NINF), INF)
1336 self.assertEqual(math.pow(-1.1, NINF), 0.)
1337 self.assertEqual(math.pow(-1.9, NINF), 0.)
1344 self.assertEqual(math.pow(-0.1, INF), 0.)
1345 self.assertEqual(math.pow(-0.9, INF), 0.)
1346 self.assertEqual(math.pow(-1.1, INF), INF)
1347 self.assertEqual(math.pow(-1.9, INF), INF)
1350 self.ftest('(-2.)**3.', math.pow(-2.0, 3.0), -8.0)
1351 self.ftest('(-2.)**2.', math.pow(-2.0, 2.0), 4.0)
1352 self.ftest('(-2.)**1.', math.pow(-2.0, 1.0), -2.0)
1353 self.ftest('(-2.)**0.', math.pow(-2.0, 0.0), 1.0)
1354 self.ftest('(-2.)**-0.', math.pow(-2.0, -0.0), 1.0)
1355 self.ftest('(-2.)**-1.', math.pow(-2.0, -1.0), -0.5)
1356 self.ftest('(-2.)**-2.', math.pow(-2.0, -2.0), 0.25)
1357 self.ftest('(-2.)**-3.', math.pow(-2.0, -3.0), -0.125)
1358 self.assertRaises(ValueError, math.pow, -2.0, -0.5)
1359 self.assertRaises(ValueError, math.pow, -2.0, 0.5)
1377 self.ftest('radians(-45)', math.radians(-45), -math.pi/4)
1392 # x - r should be an exact integer multiple of y
1393 n = (fx - fr) / fy
1401 # Remainders modulo 1, showing the ties-to-even behaviour.
1402 '-4.0 1 -0.0',
1403 '-3.8 1 0.8',
1404 '-3.0 1 -0.0',
1405 '-2.8 1 -0.8',
1406 '-2.0 1 -0.0',
1407 '-1.8 1 0.8',
1408 '-1.0 1 -0.0',
1409 '-0.8 1 -0.8',
1410 '-0.0 1 -0.0',
1414 ' 1.8 1 -0.8',
1418 ' 3.8 1 -0.8',
1426 '0x1.921fb54442d19p+1 0x1.921fb54442d18p+2 -0x1.921fb54442d17p+1',
1427 '0x1.921fb54442d17p+2 0x1.921fb54442d18p+2 -0x0.0000000000001p+2',
1431 '0x1.2d97c7f3321d2p+3 0x1.921fb54442d18p+2 -0x1.921fb54442d18p+1',
1432 '0x1.2d97c7f3321d3p+3 0x1.921fb54442d18p+2 -0x1.921fb54442d14p+1',
1433 '0x1.921fb54442d17p+3 0x1.921fb54442d18p+2 -0x0.0000000000001p+3',
1438 '0x1.f6a7a2955385fp+3 0x1.921fb54442d18p+2 -0x1.921fb54442d14p+1',
1440 '0x1.1475cc9eedf01p+5 0x1.921fb54442d18p+2 -0x1.921fb54442d10p+1',
1444 '-1 0.c -0.4',
1445 ' 1 -0.c 0.4',
1446 '-1 -0.c -0.4',
1447 ' 1.4 0.c -0.4',
1448 '-1.4 0.c 0.4',
1449 ' 1.4 -0.c -0.4',
1450 '-1.4 -0.c 0.4',
1455 '0x1.ep+1023 0x1.4p+1023 -0x0.ap+1023',
1456 '0x1.fp+1023 0x1.4p+1023 -0x0.9p+1023',
1474 tiny = float.fromhex('1p-1074') # min +ve subnormal
1475 for n in range(-25, 25):
1483 actual = math.remainder(-x, y)
1484 validate_spec(-x, y, actual)
1488 for value in [NAN, 0.0, -0.0, 2.0, -2.3, NINF, INF]:
1492 # remainder(x, inf) is x, for non-nan non-infinite x.
1493 for value in [-2.3, -0.0, 0.0, 2.3]:
1497 # remainder(x, 0) and remainder(infinity, x) for non-NaN x are invalid
1498 # operations according to IEEE 754-2008 7.2(f), and should raise.
1499 for value in [NINF, -2.3, -0.0, 0.0, 2.3, INF]:
1507 math.remainder(value, -0.0)
1513 self.ftest('sin(-pi/2)', math.sin(-math.pi/2), -1)
1525 self.ftest('sinh(1)**2-cosh(1)**2', math.sinh(1)**2-math.cosh(1)**2, -1)
1526 self.ftest('sinh(1)+sinh(-1)', math.sinh(1)+math.sinh(-1), 0)
1541 self.assertRaises(ValueError, math.sqrt, -1)
1549 self.ftest('tan(-pi/4)', math.tan(-math.pi/4), -1)
1561 self.ftest('tanh(1)+tanh(-1)', math.tanh(1)+math.tanh(-1), 0,
1564 self.ftest('tanh(-inf)', math.tanh(NINF), -1)
1569 # check that tanh(-0.) == -0. on IEEE 754 systems
1570 self.assertEqual(math.tanh(-0.), -0.)
1571 self.assertEqual(math.copysign(1., math.tanh(-0.)),
1572 math.copysign(1., -0.))
1576 self.assertEqual(math.trunc(-1), -1)
1580 self.assertEqual(math.trunc(-1.5), -1)
1582 self.assertEqual(math.trunc(-1.999999), -1)
1583 self.assertEqual(math.trunc(-0.999999), -0)
1584 self.assertEqual(math.trunc(-100.999), -100)
1605 self.assertTrue(math.isfinite(-0.0))
1607 self.assertTrue(math.isfinite(-1.0))
1610 self.assertFalse(math.isfinite(float("-inf")))
1614 self.assertTrue(math.isnan(float("-nan")))
1622 self.assertTrue(math.isinf(float("-inf")))
1624 self.assertTrue(math.isinf(-1E400))
1638 self.assertEqual(-math.inf, float("-inf"))
1640 # RED_FLAG 16-Oct-2000 Tim
1648 x = math.exp(-1000000000)
1657 # If this fails, probably using a strict IEEE-754 conforming libm, and x
1671 x = math.sqrt(-1.0)
1675 self.fail("sqrt(-1) didn't raise ValueError")
1708 if 'invalid' in flags or 'divide-by-zero' in flags:
1742 if 'invalid' in flags or 'divide-by-zero' in flags:
1769 abs_tol = 1e-15
1772 # erfc has less-than-ideal accuracy for large
1774 # error involved in computing exp(-x*x).
1814 # Test overflow in fast-path for integers
1816 # Test overflow in fast-path for floats
1837 prod([10, 20], 1) # start is a keyword-only argument
1852 iterable = range(-10000, -1)
1854 iterable = range(-1000, 1000)
1861 iterable = [float(x) for x in range(-1000, -1)]
1863 iterable = [float(x) for x in range(-1000, 1000)]
1872 self.assertIsNaN(prod([1, float("-inf"), float("nan"),3]))
1874 self.assertIsNaN(prod([1, float("nan"), float("-inf"),3]))
1876 self.assertEqual(prod([1, 2, 3, float('inf'),-3,4]), float('-inf'))
1877 self.assertEqual(prod([1, 2, 3, float('-inf'),-3,4]), float('inf'))
1879 self.assertIsNaN(prod([1,2,0,float('inf'), -3, 4]))
1880 self.assertIsNaN(prod([1,2,0,float('-inf'), -3, 4]))
1881 self.assertIsNaN(prod([1, 2, 3, float('inf'), -3, 0, 3]))
1882 self.assertIsNaN(prod([1, 2, 3, float('-inf'), -3, 0, 2]))
1900 factorial(n) // factorial(n - k))
1905 self.assertEqual(perm(n, k), perm(n - 1, k - 1) * k + perm(n - 1, k))
1918 # Raises TypeError if any argument is non-integer or argument count is
1932 self.assertRaises(ValueError, perm, -1, 1)
1933 self.assertRaises(ValueError, perm, -2**1000, 1)
1934 self.assertRaises(ValueError, perm, 1, -1)
1935 self.assertRaises(ValueError, perm, 1, -2**1000)
1944 self.assertEqual(perm(n, 2), n * (n-1))
1964 // (factorial(k) * factorial(n - k)))
1969 self.assertEqual(comb(n, k), comb(n - 1, k - 1) + comb(n - 1, k))
1978 self.assertEqual(comb(n, n - 1), n)
1983 self.assertEqual(comb(n, k), comb(n, n - k))
1985 # Raises TypeError if any argument is non-integer or argument count is
1999 self.assertRaises(ValueError, comb, -1, 1)
2000 self.assertRaises(ValueError, comb, -2**1000, 1)
2001 self.assertRaises(ValueError, comb, 1, -1)
2002 self.assertRaises(ValueError, comb, 1, -2**1000)
2011 self.assertEqual(comb(n, 2), n * (n-1) // 2)
2013 self.assertEqual(comb(n, n-1), n)
2014 self.assertEqual(comb(n, n-2), n * (n-1) // 2)
2030 self.assertEqual(math.nextafter(4503599627370496.0, -INF),
2036 self.assertEqual(math.nextafter(-9223372036854775808.0, 0.0),
2037 -9223372036854774784.0)
2040 self.assertEqual(math.nextafter(1.0, -INF),
2041 float.fromhex('0x1.fffffffffffffp-1'))
2047 self.assertEqualSign(math.nextafter(-0.0, +0.0), +0.0)
2048 self.assertEqualSign(math.nextafter(+0.0, -0.0), -0.0)
2053 self.assertEqual(math.nextafter(-0.0, INF), smallest_subnormal)
2054 self.assertEqual(math.nextafter(+0.0, -INF), -smallest_subnormal)
2055 self.assertEqual(math.nextafter(-0.0, -INF), -smallest_subnormal)
2057 self.assertEqualSign(math.nextafter(-smallest_subnormal, +0.0), -0.0)
2058 self.assertEqualSign(math.nextafter(smallest_subnormal, -0.0), +0.0)
2059 self.assertEqualSign(math.nextafter(-smallest_subnormal, -0.0), -0.0)
2064 self.assertEqual(math.nextafter(-INF, 0.0), -largest_normal)
2066 self.assertEqual(math.nextafter(-largest_normal, -INF), -INF)
2085 FLOAT_MAX - math.nextafter(FLOAT_MAX, -INF))
2091 # negative number: ulp(-x) == ulp(x)
2094 self.assertEqual(math.ulp(-x), math.ulp(x))
2149 self.assertIsClose(1, 1, rel_tol=-1e-100)
2151 self.assertIsClose(1, 1, rel_tol=1e-100, abs_tol=-1e10)
2157 (1.123e-300, 1.123e-300),
2159 (0.0, -0.0),
2164 # examples that are close to 1e-8, but not 1e-9
2166 (-1e-8, -1.000000009e-8),
2168 self.assertAllClose(eight_decimal_places_examples, rel_tol=1e-8)
2169 self.assertAllNotClose(eight_decimal_places_examples, rel_tol=1e-9)
2173 near_zero_examples = [(1e-9, 0.0),
2174 (-1e-9, 0.0),
2175 (-1e-150, 0.0)]
2178 # these should be close to abs_tol=1e-8
2179 self.assertAllClose(near_zero_examples, abs_tol=1e-8)
2182 # these are close regardless of tolerance -- i.e. they are equal
2191 (NAN, 1e-100),
2192 (1e-100, NAN),
2206 (-3.4, -3.4),
2207 (-1e-300, -1e-300)]
2224 self.assertAllClose(integer_examples, rel_tol=1e-8)
2225 self.assertAllNotClose(integer_examples, rel_tol=1e-9)
2232 (Decimal('1.00000001e-20'), Decimal('1.0e-20')),
2233 (Decimal('1.00000001e-100'), Decimal('1.0e-100')),
2235 self.assertAllClose(decimal_examples, rel_tol=1e-8)
2236 self.assertAllNotClose(decimal_examples, rel_tol=1e-9)
2246 self.assertAllClose(fraction_examples, rel_tol=1e-8)
2247 self.assertAllNotClose(fraction_examples, rel_tol=1e-9)