Skip to content

Commit 4851c7e

Browse files
committed
VirtualMachine: Adapt rounding behavior to Scratch
1 parent 3b11dcc commit 4851c7e

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/engine/virtualmachine.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,8 +431,12 @@ do_loop_end : {
431431

432432
do_round : {
433433
const Value *v = READ_REG(0, 1);
434-
if (!v->isInfinity() && !v->isNegativeInfinity())
435-
REPLACE_RET_VALUE(static_cast<long>(std::round(v->toDouble())), 1);
434+
if (!v->isInfinity() && !v->isNegativeInfinity()) {
435+
if (v->toDouble() < 0) {
436+
REPLACE_RET_VALUE(static_cast<long>(std::floor(v->toDouble() + 0.5)), 1);
437+
} else
438+
REPLACE_RET_VALUE(static_cast<long>(v->toDouble() + 0.5), 1);
439+
}
436440
DISPATCH();
437441
}
438442

0 commit comments

Comments
 (0)