math_domain_special.py 932 B

123456789101112131415161718192021222324252627282930313233343536
  1. # Tests domain errors in special math functions
  2. try:
  3. import math
  4. math.erf
  5. except (ImportError, AttributeError):
  6. print("SKIP")
  7. raise SystemExit
  8. inf = float('inf')
  9. nan = float('nan')
  10. # single argument functions
  11. for name, f, args in (
  12. ('expm1', math.exp, ()),
  13. ('log2', math.log2, (-1, 0)),
  14. ('log10', math.log10, (-1, 0)),
  15. ('sinh', math.sinh, ()),
  16. ('cosh', math.cosh, ()),
  17. ('tanh', math.tanh, ()),
  18. ('asinh', math.asinh, ()),
  19. ('acosh', math.acosh, (-1, 0.9, 1)),
  20. ('atanh', math.atanh, (-1, 1)),
  21. ('erf', math.erf, ()),
  22. ('erfc', math.erfc, ()),
  23. ('gamma', math.gamma, (-2, -1, 0, 1)),
  24. ('lgamma', math.lgamma, (-2, -1, 0, 1)),
  25. ):
  26. for x in args + (inf, nan):
  27. try:
  28. ans = f(x)
  29. print('%.4f' % ans)
  30. except ValueError:
  31. print(name, 'ValueError')
  32. except OverflowError:
  33. print(name, 'OverflowError')