2022-04-22 00:07:38 +08:00
|
|
|
|
2022-05-06 10:46:40 +08:00
|
|
|
## `from math import *` not supported anymore
|
|
|
|
|
|
|
|
import math as m
|
|
|
|
from math import abs, round, log10,
|
|
|
|
floor, ceil
|
2022-04-22 00:07:38 +08:00
|
|
|
|
|
|
|
assert(ceil(1.1) == floor(2.9))
|
|
|
|
|
|
|
|
## FIXME:
|
|
|
|
## temproarly modules cannot define globals via native interface
|
|
|
|
## and it'll be fixed soon.
|
|
|
|
PI = 3.14159265358979323846
|
|
|
|
|
2022-05-06 10:46:40 +08:00
|
|
|
assert(m.sin(0) == 0)
|
|
|
|
assert(m.sin(PI/2) == 1)
|
2022-04-22 00:07:38 +08:00
|
|
|
|
|
|
|
threshold = 0.0000000000001
|
|
|
|
|
2022-05-06 10:46:40 +08:00
|
|
|
assert(abs(m.cos(PI/3) - 0.5) < threshold )
|
|
|
|
assert(abs(m.tan(PI/4) - 1.0) < threshold )
|
2022-04-22 00:07:38 +08:00
|
|
|
for i in 0..1000
|
2022-05-06 10:46:40 +08:00
|
|
|
assert(abs(m.sin(i) / m.cos(i) - m.tan(i)) < threshold)
|
2022-04-22 00:07:38 +08:00
|
|
|
end
|
|
|
|
|
2022-05-06 10:46:40 +08:00
|
|
|
assert((m.cosh(.5) - 1.1276259652063807) < threshold)
|
|
|
|
assert((m.tanh(0.5) - 1.127625965206) < threshold)
|
2022-04-22 00:07:38 +08:00
|
|
|
for i in 0..100
|
2022-05-06 10:46:40 +08:00
|
|
|
assert(abs(m.sinh(i) / m.cosh(i) - m.tanh(i)) < threshold)
|
2022-04-22 00:07:38 +08:00
|
|
|
end
|
|
|
|
|
2022-05-06 10:46:40 +08:00
|
|
|
assert(abs(m.acos(PI/4) - 0.5) < 0.35)
|
|
|
|
assert(abs(m.atan(PI/4) - 0.5) < 0.2)
|
2022-04-22 00:07:38 +08:00
|
|
|
|
2022-05-06 10:46:40 +08:00
|
|
|
assert((m.acos(0.5) - 1.1276259652063807) < threshold)
|
|
|
|
assert((m.atan(0.3) - 1.1276259652063807) < threshold)
|
2022-04-22 00:07:38 +08:00
|
|
|
|
|
|
|
x = -1; interval = 1000
|
|
|
|
for i in 0..interval-1
|
|
|
|
x += 2/interval
|
2022-05-06 10:46:40 +08:00
|
|
|
assert(abs(m.sin(m.asin(x)) - x) < threshold)
|
|
|
|
assert(abs(m.cos(m.acos(x)) - x) < threshold)
|
|
|
|
assert(abs(m.tan(m.atan(x)) - x) < threshold)
|
2022-04-22 00:07:38 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
assert(abs(log10(2) - 0.3010299956639812) < threshold)
|
|
|
|
assert(round(1.4) == 1)
|
|
|
|
assert(round(1.5) == 2)
|
|
|
|
assert(round(-1.5) == -2)
|
|
|
|
|
|
|
|
## Note that these mathe functions are removed temproarly from the core
|
|
|
|
## For more information see PR #201
|
|
|
|
##
|
|
|
|
##assert(abs(log2(2) - 1) < threshold)
|
|
|
|
##assert(abs(log2(1) - 0) < threshold)
|
|
|
|
##assert(abs(log2(5) - 2.321928094887362) < threshold)
|
|
|
|
##
|
|
|
|
##assert(abs(hypot(1,1) - 1.414213562373095) < threshold)
|
|
|
|
##assert(abs(hypot(3,5) - 5.830951894845301) < threshold)
|
|
|
|
##
|
|
|
|
##assert(abs(cbrt(27) - 3) < threshold)
|
|
|
|
##assert(abs(cbrt(9) - 2.080083823051904) < threshold)
|
|
|
|
##
|
|
|
|
##assert(abs(gamma(5) - 24) < threshold)
|
|
|
|
##assert(abs(gamma(2.2) - 1.101802490879713) < threshold)
|
|
|
|
|
|
|
|
# If we got here, that means all test were passed.
|
|
|
|
print('All TESTS PASSED')
|