aboutsummaryrefslogtreecommitdiff
path: root/bc_funcs/trig.bc
diff options
context:
space:
mode:
author0ceanlight <imahacubak@gmail.com>2021-01-03 23:33:47 +0000
committer0ceanlight <imahacubak@gmail.com>2021-01-03 23:33:47 +0000
commit29c57f70097717c95d5e1656937701725e73a45a (patch)
treef4f6bda57732ab9537a87018d18caf2cb3062bfd /bc_funcs/trig.bc
parent7ef50546a8938612ca8f3e208cabf6d9eac8017c (diff)
parentdebe83ad9d540927f92783a8032caf99fe4c5443 (diff)
downloadsteve-bot-29c57f70097717c95d5e1656937701725e73a45a.tar
steve-bot-29c57f70097717c95d5e1656937701725e73a45a.tar.gz
steve-bot-29c57f70097717c95d5e1656937701725e73a45a.tar.bz2
steve-bot-29c57f70097717c95d5e1656937701725e73a45a.tar.lz
steve-bot-29c57f70097717c95d5e1656937701725e73a45a.tar.xz
steve-bot-29c57f70097717c95d5e1656937701725e73a45a.tar.zst
steve-bot-29c57f70097717c95d5e1656937701725e73a45a.zip
Merge branch 'master' of https://github.com/MCBE-Speedrunning/Steve-Bot into fair
Diffstat (limited to 'bc_funcs/trig.bc')
-rw-r--r--bc_funcs/trig.bc98
1 files changed, 98 insertions, 0 deletions
diff --git a/bc_funcs/trig.bc b/bc_funcs/trig.bc
new file mode 100644
index 0000000..9a4fcb3
--- /dev/null
+++ b/bc_funcs/trig.bc
@@ -0,0 +1,98 @@
+define sin(x) {
+ auto b, s, r, a, q, i
+
+ if (x < 0)
+ return (-sin(-x))
+
+ b = ibase
+ ibase = A
+ s = scale
+ scale = 1.1 * s + 2
+ a = atan(1)
+ scale = 0
+ q = (x / a + 2) / 4
+ x -= 4 * q * a
+
+ if (q % 2)
+ x = -x
+
+ scale = s + 2
+ r = a = x
+ q = -x * x
+
+ for (i = 3; a; i += 2) {
+ a *= q / (i * (i - 1))
+ r += a
+ }
+
+ scale = s
+ ibase = b
+ return (r / 1)
+}
+
+define cos(x) {
+ auto b, s
+ b = ibase
+ ibase = A
+ s = scale
+ scale *= 1.2
+ x = sin(2 * atan(1) + x)
+ scale = s
+ ibase = b
+
+ return (x / 1)
+}
+
+define atan(x) {
+ auto b, s, r, n, a, m, t, f, i, u
+ b = ibase
+ ibase = A
+ n = 1
+
+ if (x < 0) {
+ n = -1
+ x = -x
+ }
+
+ if (scale < 65) {
+ if (x == 1) {
+ r = .7853981633974483096156608458198757210492923498437764552437361480/n
+ ibase = b
+ return (r)
+ }
+
+ if (x == .2) {
+ r = .1973955598498807583700497651947902934475851037878521015176889402/n
+ ibase = b
+ return (r)
+ }
+ }
+
+ s = scale
+
+ if (x > .2) {
+ scale += 5
+ a = atan(.2)
+ }
+
+ scale = s + 3
+
+ while (x > .2) {
+ m += 1
+ x = (x - .2) / (1 + .2 * x)
+ }
+
+ r = u = x
+ f = -x * x
+ t = 1
+
+ for (i = 3; t; i += 2) {
+ u *= f
+ t = u / i
+ r += t
+ }
+
+ scale = s
+ ibase = b
+ return ((m * a + r) / n)
+}