Skip to content

Handle modulo by 0#1663

Open
bioball wants to merge 1 commit into
apple:mainfrom
bioball:modulo-by-zero
Open

Handle modulo by 0#1663
bioball wants to merge 1 commit into
apple:mainfrom
bioball:modulo-by-zero

Conversation

@bioball
Copy link
Copy Markdown
Member

@bioball bioball commented Jun 6, 2026

Treat modulo by zero as division by zero

NOTE: This copies the behavior of int div, but not division.

pkl0> 5 / 0
Infinity
pkl1> 5 ~/ 0
–– Pkl Error ––
Division by zero.

1 | 5 ~/ 0
    ^^^^^^
at  (repl:pkl1)

Should we copy division or integer division?

My sense is that throw is the better behavior here. I'm not sure when 5 % 0 resulting in Infinity is meaningful.

Perhaps we should fix the division case too.

Fixes #1660

Treat modulo by zero as division by zero

NOTE: This copies the behavior of int div, but not division.
@HT154 HT154 changed the title Handle module by 0 Handle modulo by 0 Jun 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Modulo operator with 0 produces crash

2 participants