def up32
import bend-collections-laws-math@1.0.0.0/src/math/w64.bend as W64import Base
442# r + 1 while r < 65535 and (r + 1)^2 <= x: at most 65535 - r steps
443def up32(fuel: Nat, +x: U32, +r: U32, up: Bool) -> U32:
444 match fuel up:
445 case 0n _:
446 r
447 case 1n+f False{}:
448 r
449 case 1n+f True{}:
450 up32(f, x, U32.add(r, 1), up_ok(x, U32.add(r, 1)))