Arithmetic overflow

This script, which divides two numbers ends up giving error “execution error, arithmetic overflow”. Is that normal ? Can’t find anything in documentation about that.

var c:Nat = 0;
while(c < 100000) {
Debug.print("test...." #  Nat.toText(c) # "  " # Nat32.toText(136/32));
c := c + 1;

Right before the end it prints
test…65471 160
test…65472 160
test…65473 160
test…65474 160

That indeed looks like a bug. Is this in compiled code or the interpreter?

I’m on vacation but opened an issue.

The command I use is

 moc -r `vessel sources` 

I have isolated it to this, which also gives the error.

import Nat32 "mo:base/Nat32";

loop {
ignore Nat32.toText(136/32);

The bug occurs with Int64,Nat64,Nat32 and similar…, but doesn’t occur with Int.toText and Nat.toText

Sometimes I see it pointing:
“/src/ execution error, arithmetic overflow”

The -r option instructs moc to run your snippet in the interpreter. I have seen cases where loops were restricted to a certain number of iterations (maybe due to the interpreter not being tail-recursive in that case). My hunch is that the tight stack situation might crosstalk into the arithmetic evaluator.

Please note that the interpreter was only intended to try out ideas by running toy snippets/programs. It is not up to the same standards as the compiler, and has a number of shortcomings.