From c43310f316d35e37d7617dd8cb0a99f319e12e48 Mon Sep 17 00:00:00 2001 From: Add00 Date: Mon, 31 Jul 2023 13:13:10 -0400 Subject: [PATCH] Code clean up --- repl/lib_standard.c | 8 +++++--- test/scripts/lib/standard.toy | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/repl/lib_standard.c b/repl/lib_standard.c index 8d35f50..1c261b1 100644 --- a/repl/lib_standard.c +++ b/repl/lib_standard.c @@ -706,6 +706,7 @@ static int nativeSin(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) //cleanup Toy_freeLiteral(resultLiteral); + Toy_freeLiteral(valueLiteral); return 1; } @@ -741,9 +742,9 @@ static int nativeCos(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) float power = value; int sign = 1; - for (int n = 1; n <= 10; n += 2) { - result += sign * power / n; - power = power * value * value; + for (int n = 0; n <= 10; n += 2) { + result += sign * power; + power = power * value * value / ((n + 1) * (n + 2)); sign = -sign; } @@ -753,6 +754,7 @@ static int nativeCos(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments) //cleanup Toy_freeLiteral(resultLiteral); + Toy_freeLiteral(valueLiteral); return 1; } diff --git a/test/scripts/lib/standard.toy b/test/scripts/lib/standard.toy index 4233bd3..c068468 100644 --- a/test/scripts/lib/standard.toy +++ b/test/scripts/lib/standard.toy @@ -143,8 +143,8 @@ import standard; assert clamp(0.0, 1.0, 5.0) == 1, "clamp(0.0, 1.0, 5.0) failed"; assert clamp(10.0, 1.0, 5.0) == 5, "clamp(10.0, 1.0, 5.0) failed"; - // assert typeof clamp(10, 1, 5) == int, "typeof clamp(10, 1, 5) == int failed"; - // assert typeof clamp(10.0, 1, 5) == int, "typeof clamp(10.0, 1, 5) == int failed"; + assert typeof clamp(10, 1, 5) == int, "typeof clamp(10, 1, 5) == int failed"; + assert typeof clamp(10.0, 1, 5) == int, "typeof clamp(10.0, 1, 5) == int failed"; assert typeof clamp(10, 1, 5.0) == float, "typeof clamp(10, 1, 5.0) == float failed"; }