mirror of
https://github.com/zekexiao/pocketlang.git
synced 2025-02-06 04:37:47 +08:00
65 lines
1.7 KiB
Plaintext
65 lines
1.7 KiB
Plaintext
|
|
from math import *
|
|
|
|
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
|
|
|
|
assert(sin(0) == 0)
|
|
assert(sin(PI/2) == 1)
|
|
|
|
threshold = 0.0000000000001
|
|
|
|
assert(abs(cos(PI/3) - 0.5) < threshold )
|
|
assert(abs(tan(PI/4) - 1.0) < threshold )
|
|
for i in 0..1000
|
|
assert(abs(sin(i) / cos(i) - tan(i)) < threshold)
|
|
end
|
|
|
|
assert((cosh(.5) - 1.1276259652063807) < threshold)
|
|
assert((tanh(0.5) - 1.127625965206) < threshold)
|
|
for i in 0..100
|
|
assert(abs(sinh(i) / cosh(i) - tanh(i)) < threshold)
|
|
end
|
|
|
|
assert(abs(acos(PI/4) - 0.5) < 0.35)
|
|
assert(abs(atan(PI/4) - 0.5) < 0.2)
|
|
|
|
assert((acos(0.5) - 1.1276259652063807) < threshold)
|
|
assert((atan(0.3) - 1.1276259652063807) < threshold)
|
|
|
|
x = -1; interval = 1000
|
|
for i in 0..interval-1
|
|
x += 2/interval
|
|
assert(abs(sin(asin(x)) - x) < threshold)
|
|
assert(abs(cos(acos(x)) - x) < threshold)
|
|
assert(abs(tan(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')
|