Code clean up

This commit is contained in:
Add00
2023-07-31 13:13:10 -04:00
parent 5317a12383
commit c43310f316
2 changed files with 7 additions and 5 deletions

View File

@@ -706,6 +706,7 @@ static int nativeSin(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments)
//cleanup //cleanup
Toy_freeLiteral(resultLiteral); Toy_freeLiteral(resultLiteral);
Toy_freeLiteral(valueLiteral);
return 1; return 1;
} }
@@ -741,9 +742,9 @@ static int nativeCos(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments)
float power = value; float power = value;
int sign = 1; int sign = 1;
for (int n = 1; n <= 10; n += 2) { for (int n = 0; n <= 10; n += 2) {
result += sign * power / n; result += sign * power;
power = power * value * value; power = power * value * value / ((n + 1) * (n + 2));
sign = -sign; sign = -sign;
} }
@@ -753,6 +754,7 @@ static int nativeCos(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments)
//cleanup //cleanup
Toy_freeLiteral(resultLiteral); Toy_freeLiteral(resultLiteral);
Toy_freeLiteral(valueLiteral);
return 1; return 1;
} }

View File

@@ -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(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 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, 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.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"; assert typeof clamp(10, 1, 5.0) == float, "typeof clamp(10, 1, 5.0) == float failed";
} }