1# Tests domain errors in math functions
2
3try:
4    import math
5except ImportError:
6    print("SKIP")
7    raise SystemExit
8
9inf = float("inf")
10nan = float("nan")
11
12# single argument functions
13for name, f, args in (
14    ("fabs", math.fabs, ()),
15    ("ceil", math.ceil, ()),
16    ("floor", math.floor, ()),
17    ("trunc", math.trunc, ()),
18    ("sqrt", math.sqrt, (-1, 0)),
19    ("exp", math.exp, ()),
20    ("sin", math.sin, ()),
21    ("cos", math.cos, ()),
22    ("tan", math.tan, ()),
23    ("asin", math.asin, (-1.1, 1, 1.1)),
24    ("acos", math.acos, (-1.1, 1, 1.1)),
25    ("atan", math.atan, ()),
26    ("ldexp", lambda x: math.ldexp(x, 0), ()),
27    ("radians", math.radians, ()),
28    ("degrees", math.degrees, ()),
29):
30    for x in args + (inf, nan):
31        try:
32            ans = f(x)
33            print("%.4f" % ans)
34        except ValueError:
35            print(name, "ValueError")
36        except OverflowError:
37            print(name, "OverflowError")
38
39# double argument functions
40for name, f, args in (
41    ("pow", math.pow, ((0, 2), (-1, 2), (0, -1), (-1, 2.3), (nan, 0), (1, nan))),
42    ("fmod", math.fmod, ((1.2, inf), (1.2, -inf), (1.2, 0), (inf, 1.2))),
43    ("atan2", math.atan2, ((0, 0), (-inf, inf), (-inf, -inf), (inf, -inf))),
44    ("copysign", math.copysign, ()),
45):
46    for x in args + ((0, inf), (inf, 0), (inf, inf), (inf, nan), (nan, inf), (nan, nan)):
47        try:
48            ans = f(*x)
49            print("%.4f" % ans)
50        except ValueError:
51            print(name, "ValueError")
52