2023-10-10 16:56:38 +08:00
|
|
|
@extern
|
|
|
|
def output_bool(x: bool):
|
|
|
|
...
|
|
|
|
|
2023-11-02 14:56:35 +08:00
|
|
|
@extern
|
|
|
|
def output_int32(x: int32):
|
|
|
|
...
|
|
|
|
|
|
|
|
@extern
|
|
|
|
def output_int64(x: int64):
|
|
|
|
...
|
|
|
|
|
2023-10-06 17:48:31 +08:00
|
|
|
@extern
|
|
|
|
def output_float64(x: float):
|
|
|
|
...
|
|
|
|
|
2023-10-10 16:56:38 +08:00
|
|
|
@extern
|
|
|
|
def dbl_nan() -> float:
|
|
|
|
...
|
|
|
|
|
|
|
|
@extern
|
|
|
|
def dbl_inf() -> float:
|
|
|
|
...
|
|
|
|
|
2023-10-11 17:52:12 +08:00
|
|
|
def dbl_pi() -> float:
|
|
|
|
return 3.1415926535897932384626433
|
|
|
|
|
|
|
|
def dbl_e() -> float:
|
|
|
|
return 2.71828182845904523536028747135266249775724709369995
|
|
|
|
|
2023-11-02 14:56:35 +08:00
|
|
|
def test_round():
|
|
|
|
for x in [-1.5, -0.5, 0.5, 1.5]:
|
|
|
|
output_int32(round(x))
|
|
|
|
|
|
|
|
def test_round64():
|
|
|
|
for x in [-1.5, -0.5, 0.5, 1.5]:
|
|
|
|
output_int64(round64(x))
|
|
|
|
|
2023-10-10 16:56:38 +08:00
|
|
|
def test_isnan():
|
|
|
|
for x in [dbl_nan(), 0.0, dbl_inf()]:
|
|
|
|
output_bool(isnan(x))
|
|
|
|
|
|
|
|
def test_isinf():
|
2023-10-11 17:52:12 +08:00
|
|
|
for x in [dbl_inf(), -dbl_inf(), 0.0, dbl_nan()]:
|
2023-10-10 16:56:38 +08:00
|
|
|
output_bool(isinf(x))
|
|
|
|
|
2023-10-06 17:48:31 +08:00
|
|
|
def test_sin():
|
2023-10-11 17:52:12 +08:00
|
|
|
pi = dbl_pi()
|
|
|
|
for x in [-pi, -pi / 2.0, -pi / 4.0, 0.0, pi / 4.0, pi / 2.0, pi, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-10-06 17:48:31 +08:00
|
|
|
output_float64(sin(x))
|
|
|
|
|
|
|
|
def test_cos():
|
2023-10-11 17:52:12 +08:00
|
|
|
pi = dbl_pi()
|
|
|
|
for x in [-pi, -pi / 2.0, -pi / 4.0, 0.0, pi / 4.0, pi / 2.0, pi, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-10-06 17:48:31 +08:00
|
|
|
output_float64(cos(x))
|
|
|
|
|
|
|
|
def test_exp():
|
2023-10-11 17:52:12 +08:00
|
|
|
for x in [0.0, 1.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-10-06 17:48:31 +08:00
|
|
|
output_float64(exp(x))
|
|
|
|
|
|
|
|
def test_exp2():
|
2023-10-11 17:52:12 +08:00
|
|
|
for x in [0.0, 1.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-10-06 17:48:31 +08:00
|
|
|
output_float64(exp2(x))
|
|
|
|
|
|
|
|
def test_log():
|
2023-10-11 17:52:12 +08:00
|
|
|
e = dbl_e()
|
|
|
|
for x in [1.0, e, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-10-06 17:48:31 +08:00
|
|
|
output_float64(log(x))
|
|
|
|
|
|
|
|
def test_log10():
|
2023-10-11 17:52:12 +08:00
|
|
|
for x in [1.0, 10.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-10-06 17:48:31 +08:00
|
|
|
output_float64(log10(x))
|
|
|
|
|
|
|
|
def test_log2():
|
2023-10-11 17:52:12 +08:00
|
|
|
for x in [1.0, 2.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-10-06 17:48:31 +08:00
|
|
|
output_float64(log2(x))
|
|
|
|
|
|
|
|
def test_fabs():
|
2023-10-11 17:52:12 +08:00
|
|
|
for x in [-1.0, 0.0, 1.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-10-06 17:48:31 +08:00
|
|
|
output_float64(fabs(x))
|
|
|
|
|
|
|
|
def test_floor():
|
2023-11-02 14:56:35 +08:00
|
|
|
for x in [-1.5, -0.5, 0.5, 1.5]:
|
|
|
|
output_int32(floor(x))
|
|
|
|
|
|
|
|
def test_floor64():
|
|
|
|
for x in [-1.5, -0.5, 0.5, 1.5]:
|
|
|
|
output_int64(floor64(x))
|
2023-10-06 17:48:31 +08:00
|
|
|
|
|
|
|
def test_ceil():
|
2023-11-02 14:56:35 +08:00
|
|
|
for x in [-1.5, -0.5, 0.5, 1.5]:
|
|
|
|
output_int32(ceil(x))
|
|
|
|
|
|
|
|
def test_ceil64():
|
|
|
|
for x in [-1.5, -0.5, 0.5, 1.5]:
|
|
|
|
output_int64(ceil64(x))
|
2023-10-06 17:48:31 +08:00
|
|
|
|
|
|
|
def test_sqrt():
|
2023-10-11 17:52:12 +08:00
|
|
|
for x in [1.0, 2.0, 4.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-10-06 17:48:31 +08:00
|
|
|
output_float64(sqrt(x))
|
|
|
|
|
|
|
|
def test_rint():
|
2023-10-11 17:52:12 +08:00
|
|
|
for x in [-1.5, -0.5, 0.5, 1.5, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-10-06 17:48:31 +08:00
|
|
|
output_float64(rint(x))
|
|
|
|
|
|
|
|
def test_tan():
|
2023-10-11 17:52:12 +08:00
|
|
|
pi = dbl_pi()
|
|
|
|
for x in [-pi, -pi / 2.0, -pi / 4.0, 0.0, pi / 4.0, pi / 2.0, pi, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-10-06 17:48:31 +08:00
|
|
|
output_float64(tan(x))
|
|
|
|
|
|
|
|
def test_arcsin():
|
2023-10-11 17:52:12 +08:00
|
|
|
for x in [-1.0, -0.5, 0.0, 0.5, 1.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-10-06 17:48:31 +08:00
|
|
|
output_float64(arcsin(x))
|
|
|
|
|
|
|
|
def test_arccos():
|
2023-10-11 17:52:12 +08:00
|
|
|
for x in [-1.0, -0.5, 0.0, 0.5, 1.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-10-06 17:48:31 +08:00
|
|
|
output_float64(arccos(x))
|
|
|
|
|
|
|
|
def test_arctan():
|
2023-10-11 17:52:12 +08:00
|
|
|
for x in [-1.0, -0.5, 0.0, 0.5, 1.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-10-06 17:48:31 +08:00
|
|
|
output_float64(arctan(x))
|
|
|
|
|
|
|
|
def test_sinh():
|
2023-10-11 17:52:12 +08:00
|
|
|
for x in [-1.0, -0.5, 0.0, 0.5, 1.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-10-06 17:48:31 +08:00
|
|
|
output_float64(sinh(x))
|
|
|
|
|
|
|
|
def test_cosh():
|
2023-10-11 17:52:12 +08:00
|
|
|
for x in [-1.0, -0.5, 0.0, 0.5, 1.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-10-06 17:48:31 +08:00
|
|
|
output_float64(cosh(x))
|
|
|
|
|
|
|
|
def test_tanh():
|
2023-10-11 17:52:12 +08:00
|
|
|
for x in [-1.0, -0.5, 0.0, 0.5, 1.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-10-06 17:48:31 +08:00
|
|
|
output_float64(tanh(x))
|
|
|
|
|
|
|
|
def test_arcsinh():
|
2023-10-11 17:52:12 +08:00
|
|
|
for x in [-1.0, -0.5, 0.0, 0.5, 1.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-10-06 17:48:31 +08:00
|
|
|
output_float64(arcsinh(x))
|
|
|
|
|
|
|
|
def test_arccosh():
|
2023-10-11 17:52:12 +08:00
|
|
|
for x in [-1.0, -0.5, 0.0, 0.5, 1.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-10-06 17:48:31 +08:00
|
|
|
output_float64(arccosh(x))
|
|
|
|
|
|
|
|
def test_arctanh():
|
2023-10-11 17:52:12 +08:00
|
|
|
for x in [-1.0, -0.5, 0.0, 0.5, 1.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-10-06 17:48:31 +08:00
|
|
|
output_float64(arctanh(x))
|
|
|
|
|
|
|
|
def test_expm1():
|
2023-10-11 17:52:12 +08:00
|
|
|
for x in [0.0, 1.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-10-06 17:48:31 +08:00
|
|
|
output_float64(expm1(x))
|
|
|
|
|
|
|
|
def test_cbrt():
|
2023-10-11 17:52:12 +08:00
|
|
|
for x in [1.0, 8.0, 27.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-10-06 17:48:31 +08:00
|
|
|
output_float64(expm1(x))
|
|
|
|
|
|
|
|
def test_erf():
|
2023-10-11 17:52:12 +08:00
|
|
|
for x in [-3.0, -2.0, -1.0, 0.0, 1.0, 2.0, 3.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-10-06 17:48:31 +08:00
|
|
|
output_float64(erf(x))
|
|
|
|
|
|
|
|
def test_erfc():
|
2023-10-11 17:52:12 +08:00
|
|
|
for x in [-3.0, -2.0, -1.0, 0.0, 1.0, 2.0, 3.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-10-06 17:48:31 +08:00
|
|
|
output_float64(erfc(x))
|
|
|
|
|
|
|
|
def test_gamma():
|
2023-10-11 17:52:12 +08:00
|
|
|
for x in [-2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-10-06 17:48:31 +08:00
|
|
|
output_float64(gamma(x))
|
|
|
|
|
|
|
|
def test_gammaln():
|
2023-10-11 17:52:12 +08:00
|
|
|
for x in [-2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-10-06 17:48:31 +08:00
|
|
|
output_float64(gammaln(x))
|
|
|
|
|
|
|
|
def test_j0():
|
2023-10-11 17:52:12 +08:00
|
|
|
for x in [-2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-10-06 17:48:31 +08:00
|
|
|
output_float64(j0(x))
|
|
|
|
|
|
|
|
def test_j1():
|
|
|
|
for x in [-2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0]:
|
|
|
|
output_float64(j1(x))
|
|
|
|
|
|
|
|
def test_arctan2():
|
2023-10-11 17:52:12 +08:00
|
|
|
for x1 in [-1.0, -0.5, 0.0, 0.5, 1.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
|
|
|
for x2 in [-1.0, -0.5, 0.0, 0.5, 1.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-10-06 17:48:31 +08:00
|
|
|
output_float64(arctan2(x1, x2))
|
|
|
|
|
|
|
|
def test_copysign():
|
2023-10-11 17:52:12 +08:00
|
|
|
for x1 in [-1.0, -0.5, 0.0, 0.5, 1.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
|
|
|
for x2 in [-1.0, -0.5, 0.0, 0.5, 1.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-10-06 17:48:31 +08:00
|
|
|
output_float64(copysign(x1, x2))
|
|
|
|
|
|
|
|
def test_fmax():
|
2023-10-11 17:52:12 +08:00
|
|
|
for x1 in [-1.0, -0.5, 0.0, 0.5, 1.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
|
|
|
for x2 in [-1.0, -0.5, 0.0, 0.5, 1.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-10-06 17:48:31 +08:00
|
|
|
output_float64(fmax(x1, x2))
|
|
|
|
|
|
|
|
def test_fmin():
|
2023-10-11 17:52:12 +08:00
|
|
|
for x1 in [-1.0, -0.5, 0.0, 0.5, 1.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
|
|
|
for x2 in [-1.0, -0.5, 0.0, 0.5, 1.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-10-06 17:48:31 +08:00
|
|
|
output_float64(fmin(x1, x2))
|
|
|
|
|
|
|
|
def test_ldexp():
|
2023-10-11 17:52:12 +08:00
|
|
|
for x1 in [-2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-10-06 17:48:31 +08:00
|
|
|
for x2 in [-2, -1, 0, 1, 2]:
|
|
|
|
output_float64(ldexp(x1, x2))
|
|
|
|
|
|
|
|
def test_hypot():
|
2023-10-11 17:52:12 +08:00
|
|
|
for x1 in [-2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
|
|
|
for x2 in [-2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-10-06 17:48:31 +08:00
|
|
|
output_float64(hypot(x1, x2))
|
|
|
|
|
|
|
|
def test_nextafter():
|
2023-10-11 17:52:12 +08:00
|
|
|
for x1 in [-2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
|
|
|
for x2 in [-2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0, dbl_inf(), -dbl_inf(), dbl_nan()]:
|
2023-10-06 17:48:31 +08:00
|
|
|
output_float64(nextafter(x1, x2))
|
|
|
|
|
2023-10-10 16:56:38 +08:00
|
|
|
def run() -> int32:
|
2023-11-02 14:56:35 +08:00
|
|
|
test_round()
|
|
|
|
test_round64()
|
2023-10-10 16:56:38 +08:00
|
|
|
test_isnan()
|
|
|
|
test_isinf()
|
2023-10-06 17:48:31 +08:00
|
|
|
test_sin()
|
|
|
|
test_cos()
|
|
|
|
test_exp()
|
|
|
|
test_exp2()
|
|
|
|
test_log()
|
|
|
|
test_log10()
|
|
|
|
test_log2()
|
|
|
|
test_fabs()
|
|
|
|
test_floor()
|
2023-11-02 14:56:35 +08:00
|
|
|
test_floor64()
|
2023-10-06 17:48:31 +08:00
|
|
|
test_ceil()
|
2023-11-02 14:56:35 +08:00
|
|
|
test_ceil64()
|
2023-10-06 17:48:31 +08:00
|
|
|
test_sqrt()
|
|
|
|
test_rint()
|
|
|
|
test_tan()
|
|
|
|
test_arcsin()
|
|
|
|
test_arccos()
|
|
|
|
test_arctan()
|
|
|
|
test_sinh()
|
|
|
|
test_cosh()
|
|
|
|
test_tanh()
|
|
|
|
test_arcsinh()
|
|
|
|
test_arccosh()
|
|
|
|
test_arctanh()
|
|
|
|
test_expm1()
|
|
|
|
test_cbrt()
|
|
|
|
test_erf()
|
|
|
|
test_erfc()
|
|
|
|
test_gamma()
|
|
|
|
test_gammaln()
|
|
|
|
test_j0()
|
|
|
|
test_j1()
|
|
|
|
test_arctan2()
|
|
|
|
test_copysign()
|
|
|
|
test_fmax()
|
|
|
|
test_fmin()
|
|
|
|
test_ldexp()
|
|
|
|
test_hypot()
|
|
|
|
test_nextafter()
|
2023-10-10 16:56:38 +08:00
|
|
|
|
|
|
|
return 0
|