From 010fd353d4c57bad9c6f47cac881d725a006423e Mon Sep 17 00:00:00 2001 From: Mango0x45 Date: Sun, 3 Jan 2021 16:34:23 +0100 Subject: Try to make math work with BC functions --- bc_funcs/trig.bc | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 bc_funcs/trig.bc (limited to 'bc_funcs/trig.bc') diff --git a/bc_funcs/trig.bc b/bc_funcs/trig.bc new file mode 100644 index 0000000..01b7839 --- /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++ + 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) +} \ No newline at end of file -- cgit v1.2.3 From 6beda6463cd341bbeb776f1d15aa5616d5e112e1 Mon Sep 17 00:00:00 2001 From: Mango0x45 Date: Sun, 3 Jan 2021 17:05:11 +0100 Subject: More bc functions --- bc_funcs/misc.bc | 7 +++++++ bc_funcs/trig.bc | 6 +++--- 2 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 bc_funcs/misc.bc (limited to 'bc_funcs/trig.bc') diff --git a/bc_funcs/misc.bc b/bc_funcs/misc.bc new file mode 100644 index 0000000..be838bb --- /dev/null +++ b/bc_funcs/misc.bc @@ -0,0 +1,7 @@ +define findseed() { + auto x, i + + for (i = 0; i < 12; i++) + x += (rand() % 10 < 1) + print "Your seed is a ", x, " eye" +} \ No newline at end of file diff --git a/bc_funcs/trig.bc b/bc_funcs/trig.bc index 01b7839..c127753 100644 --- a/bc_funcs/trig.bc +++ b/bc_funcs/trig.bc @@ -30,7 +30,7 @@ define sin(x) { return (r / 1) } -define cos(x){ +define cos(x) { auto b, s b = ibase ibase = A @@ -43,7 +43,7 @@ define cos(x){ return (x / 1) } -define atan(x){ +define atan(x) { auto b, s, r, n, a, m, t, f, i, u b = ibase ibase = A @@ -86,7 +86,7 @@ define atan(x){ f = -x * x t = 1 - for(i = 3; t; i += 2) { + for (i = 3; t; i += 2) { u *= f t = u / i r += t -- cgit v1.2.3 From d0747f3aca848525622cd6aa177434e8e2ef3ad3 Mon Sep 17 00:00:00 2001 From: Mango0x45 Date: Sun, 3 Jan 2021 17:13:30 +0100 Subject: Fix bugs --- bc_funcs/misc.bc | 7 ++++-- bc_funcs/trig.bc | 66 ++++++++++++++++++++++++++++---------------------------- 2 files changed, 38 insertions(+), 35 deletions(-) (limited to 'bc_funcs/trig.bc') diff --git a/bc_funcs/misc.bc b/bc_funcs/misc.bc index 7c0a9db..a768397 100644 --- a/bc_funcs/misc.bc +++ b/bc_funcs/misc.bc @@ -1,9 +1,12 @@ define void findseed() { - auto x, i + auto x, i, s + s = scale + scale = 0 for (i = 0; i < 12; i++) if (rand() % 10 < 1) - x++ + x += 1 + scale = s print "Your seed is a ", x, " eye" } diff --git a/bc_funcs/trig.bc b/bc_funcs/trig.bc index c127753..9a4fcb3 100644 --- a/bc_funcs/trig.bc +++ b/bc_funcs/trig.bc @@ -1,33 +1,33 @@ 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) + 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) { @@ -53,7 +53,7 @@ define atan(x) { n = -1 x = -x } - + if (scale < 65) { if (x == 1) { r = .7853981633974483096156608458198757210492923498437764552437361480/n @@ -74,11 +74,11 @@ define atan(x) { scale += 5 a = atan(.2) } - + scale = s + 3 while (x > .2) { - m++ + m += 1 x = (x - .2) / (1 + .2 * x) } @@ -95,4 +95,4 @@ define atan(x) { scale = s ibase = b return ((m * a + r) / n) -} \ No newline at end of file +} -- cgit v1.2.3