Skip to content

Integer Division operator #507

@Peter-Jacob

Description

@Peter-Jacob

Now that arithmetic operators are aligned with common conventions (% as remainder instead of //), it appears there is no longer a dedicated integer division operator. Is this intentional, or is there an alternative I’ve overlooked?

gap = 101
new=gap/2
say new  

This produces: 50.5

I am referring to the documented operators:

  • Under OPTIONS NUMERIC_COMMON: (which is standard)
    • % performs the remainder operation.
    • / performs integer division if both operands are integers; otherwise, it performs normal division.
    • // is not strickly a valid operator, however, to support legacy code, it is treated as an alias for %.

Given this, I would expect gap / 2 to yield 50 rather than 50.5.

At the moment, I’m using the IDIV assembler instruction as a workaround.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions