mirror of
https://github.com/zekexiao/pocketlang.git
synced 2025-02-06 20:50:55 +08:00
b5d98ca4c3
pkSetGlobal function implemented to support adding globals from the native interface. Also the PKVM slots doesn't need a runtime anymore to use them (see math.PI global to see how it works).
64 lines
1.7 KiB
Plaintext
64 lines
1.7 KiB
Plaintext
|
|
## `from math import *` not supported anymore
|
|
|
|
import math as m
|
|
from math import abs, round, log10,
|
|
floor, ceil
|
|
|
|
assert(ceil(1.1) == floor(2.9))
|
|
|
|
assert(m.sin(0) == 0)
|
|
assert(m.sin(m.PI/2) == 1)
|
|
|
|
threshold = 0.0000000000001
|
|
|
|
assert(abs(m.cos(m.PI/3) - 0.5) < threshold )
|
|
assert(abs(m.tan(m.PI/4) - 1.0) < threshold )
|
|
for i in 0..1000
|
|
assert(abs(m.sin(i) / m.cos(i) - m.tan(i)) < threshold)
|
|
end
|
|
|
|
assert((m.cosh(.5) - 1.1276259652063807) < threshold)
|
|
assert((m.tanh(0.5) - 1.127625965206) < threshold)
|
|
for i in 0..100
|
|
assert(abs(m.sinh(i) / m.cosh(i) - m.tanh(i)) < threshold)
|
|
end
|
|
|
|
assert(abs(m.acos(m.PI/4) - 0.5) < 0.35)
|
|
assert(abs(m.atan(m.PI/4) - 0.5) < 0.2)
|
|
|
|
assert((m.acos(0.5) - 1.1276259652063807) < threshold)
|
|
assert((m.atan(0.3) - 1.1276259652063807) < threshold)
|
|
|
|
x = -1; interval = 1000
|
|
for i in 0..interval-1
|
|
x += 2/interval
|
|
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)
|
|
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')
|