Weird and unpredictable effect of strokeWeight

So I’m trying my hand at generative art, with nested inscribed circles within a square.
What’s weird is that the exact same code gives wildly different output based on changing just the strokeWeight.

Here’s the link to program:

Try strokeWeights 1, 2 and 3 (and values in between)

Would really love to know what’s going on here. Interestingly there’s no obvious (to me) mapping from strokeweight to the output - value of 1 does what I want it to, 2 is completely unexpected, strokeWeight of 3 behaves as expected again. My guess is it’s a p5 bug, but I can’t think of what’s happening behind the scenes.

I tried it in Processing java mode and the code works fine. So it really has to be a bug but i don’t know how this can happen.

Here is the code for java:

float side = 400;
int[] colorMults = new int[]{3, 4, 5};

void setup() {
  size(400, 400);
  ellipseMode(RADIUS);
  rectMode(CENTER);
}

void draw() {
  background(220);
  stroke(0);
  noFill();
  side = 5;
  strokeWeight(3);
  for(int i = 1; i < 1000; i++) {
    stroke(side*colorMults[0]%255, 
           colorMults[1]%255, 
           side*colorMults[2]%255);
    rect(width/2, height/2, side, side);
    circle(width/2, height/2, side/2);
    side *= sqrt(2);
  }
}

Oh, no it isn’t a bug. You multiply the side-variable every iteration of the for-loop and thats 1000 times! This is exponetionally growth so the side-variable gets larger than the float limit. I guess the JAVA2D renderer handles this issue in an other way. You can simply fix this by decreasing the iteration count of the for loop (for me it works fine with 30).