math_fun_special.py 1001 B

1234567891011121314151617181920212223242526272829303132333435
  1. # test the special functions imported from math
  2. try:
  3. from math import *
  4. erf
  5. except (ImportError, NameError):
  6. print("SKIP")
  7. raise SystemExit
  8. test_values = [-8., -2.5, -1, -0.5, 0.0, 0.5, 2.5, 8.,]
  9. pos_test_values = [0.001, 0.1, 0.5, 1.0, 1.5, 10.,]
  10. functions = [
  11. ('expm1', expm1, test_values),
  12. ('log2', log2, test_values),
  13. ('log10', log10, test_values),
  14. ('cosh', cosh, test_values),
  15. ('sinh', sinh, test_values),
  16. ('tanh', tanh, test_values),
  17. ('acosh', acosh, [1.0, 5.0, 1.0]),
  18. ('asinh', asinh, test_values),
  19. ('atanh', atanh, [-0.99, -0.5, 0.0, 0.5, 0.99]),
  20. ('erf', erf, test_values),
  21. ('erfc', erfc, test_values),
  22. ('gamma', gamma, pos_test_values),
  23. ('lgamma', lgamma, pos_test_values + [50., 100.,]),
  24. ]
  25. for function_name, function, test_vals in functions:
  26. print(function_name)
  27. for value in test_vals:
  28. try:
  29. print("{:.4g}".format(function(value)))
  30. except ValueError as e:
  31. print(str(e))