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"; }