2014-03-20 17:26:51 -04:00
|
|
|
# Tests the functions imported from math
|
|
|
|
|
2014-06-19 18:50:49 -04:00
|
|
|
try:
|
|
|
|
from math import *
|
|
|
|
except ImportError:
|
|
|
|
print("SKIP")
|
|
|
|
import sys
|
|
|
|
sys.exit()
|
2014-03-20 17:26:51 -04:00
|
|
|
|
|
|
|
test_values = [-100., -1.23456, -1, -0.5, 0.0, 0.5, 1.23456, 100.]
|
2014-12-18 09:44:02 -05:00
|
|
|
test_values_small = [-10., -1.23456, -1, -0.5, 0.0, 0.5, 1.23456, 10.] # so we don't overflow 32-bit precision
|
2014-03-20 17:26:51 -04:00
|
|
|
p_test_values = [0.1, 0.5, 1.23456]
|
|
|
|
unit_range_test_values = [-1., -0.75, -0.5, -0.25, 0., 0.25, 0.5, 0.75, 1.]
|
|
|
|
|
2014-04-01 16:21:50 -04:00
|
|
|
functions = [('sqrt', sqrt, p_test_values),
|
2014-12-18 09:44:02 -05:00
|
|
|
('exp', exp, test_values_small),
|
|
|
|
('expm1', expm1, test_values_small),
|
2014-04-01 16:21:50 -04:00
|
|
|
('log', log, p_test_values),
|
|
|
|
('log2', log2, p_test_values),
|
|
|
|
('log10', log10, p_test_values),
|
2014-12-18 09:44:02 -05:00
|
|
|
('cosh', cosh, test_values_small),
|
|
|
|
('sinh', sinh, test_values_small),
|
|
|
|
('tanh', tanh, test_values_small),
|
2014-04-01 16:21:50 -04:00
|
|
|
('acosh', acosh, [1.0, 5.0, 1.0]),
|
|
|
|
('asinh', asinh, test_values),
|
|
|
|
('atanh', atanh, [-0.99, -0.5, 0.0, 0.5, 0.99]),
|
|
|
|
('cos', cos, test_values),
|
|
|
|
('sin', sin, test_values),
|
|
|
|
('tan', tan, test_values),
|
|
|
|
('acos', acos, unit_range_test_values),
|
|
|
|
('asin', asin, unit_range_test_values),
|
|
|
|
('atan', atan, test_values),
|
|
|
|
('ceil', ceil, test_values),
|
|
|
|
('fabs', fabs, test_values),
|
|
|
|
('floor', floor, test_values),
|
|
|
|
#('frexp', frexp, test_values),
|
|
|
|
('trunc', trunc, test_values)
|
2014-03-20 17:26:51 -04:00
|
|
|
]
|
|
|
|
|
2014-04-01 16:21:50 -04:00
|
|
|
for function_name, function, test_vals in functions:
|
|
|
|
print(function_name)
|
2014-03-20 17:26:51 -04:00
|
|
|
for value in test_vals:
|
2014-12-18 09:44:02 -05:00
|
|
|
print("{:.5g}".format(function(value)))
|
2014-03-20 17:26:51 -04:00
|
|
|
|
2014-04-01 16:21:50 -04:00
|
|
|
binary_functions = [('copysign', copysign, [(23., 42.), (-23., 42.), (23., -42.),
|
2014-03-20 17:26:51 -04:00
|
|
|
(-23., -42.), (1., 0.0), (1., -0.0)])
|
|
|
|
]
|
|
|
|
|
2014-04-01 16:21:50 -04:00
|
|
|
for function_name, function, test_vals in binary_functions:
|
|
|
|
print(function_name)
|
2014-03-22 10:39:33 -04:00
|
|
|
for value1, value2 in test_vals:
|
2014-04-02 15:04:15 -04:00
|
|
|
print("{:.7g}".format(function(value1, value2)))
|