Patched a casting error in round

This commit is contained in:
2023-02-27 23:27:11 +11:00
parent c5c0122243
commit efc1e764d2
2 changed files with 4 additions and 2 deletions

View File

@@ -349,8 +349,8 @@ static int nativeRound(Toy_Interpreter* interpreter, Toy_LiteralArray* arguments
}
if (TOY_IS_FLOAT(selfLiteral)) {
//catch the already-rounded case
if (TOY_AS_FLOAT(selfLiteral) == 0) {
result = selfLiteral;
if (TOY_AS_FLOAT(selfLiteral) == (int)TOY_AS_FLOAT(selfLiteral)) {
result = TOY_TO_INTEGER_LITERAL((int)TOY_AS_FLOAT(selfLiteral));
}
else {
result = TOY_TO_INTEGER_LITERAL( TOY_AS_FLOAT(selfLiteral) - (int)TOY_AS_FLOAT(selfLiteral) < 0.5 ? (int)TOY_AS_FLOAT(selfLiteral) : (int)TOY_AS_FLOAT(selfLiteral) + 1 );

View File

@@ -96,6 +96,8 @@ import standard;
var x = 4.1;
assert x.round() == 4, "var.round() failed";
assert typeof round(1.0) == int, "typeof round() == int failed";
}