Skip to content

Order of operations in integer arithmetic is wrong #976

@Zarkonnen

Description

@Zarkonnen

Reproduce
{ 10 * 8 / 10 }

Expected Output
8

Observed Output
0

Workaround
{ (10 * 8) / 10 }

I'd expect the order of operations to go left to right, as is generally the case with other environments/programming languages. Unfortunately, fixing this might break existing Ink scripts that rely on this behavior. Also unfortunately, there's probably a lot of scripts out in the while that have bugs in them because of this bug.

Addendum
Looking at the following examples, it seems that the problem is that division has a higher priority than multiplication, which it shouldn't:

  • Forcing right-to-left evaluation: { 10 / (2 * 2) } -> 2
  • Forcing left-to-right evaluation: { (10 / 2) * 2 } -> 10
  • Without brackets: { 10 / 2 * 2 } -> 10

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions