def u32_np

bend-collections-laws-math@1.0.0.0 · src/math/fixed.bend:222

import bend-collections-laws-math@1.0.0.0/src/math/fixed.bend as Fixed
import Base
import bend-collections-laws-math@1.0.0.0/src/math/number.bend as NB

222# the least prime above n below 2^32: the candidates n+1, n+2, ... stop at
223# the first prime or when the next candidate wraps to 0
224def u32_np(fuel: Nat, +m: U32, wrapped: Bool, prime: Bool) -> Maybe<&2, U32>:
225  match fuel wrapped prime:
226    case 0n _ _:
227      None{}
228    case 1n+f True{} _:
229      None{}
230    case 1n+f False{} True{}:
231      Some{m}
232    case 1n+ +f False{} False{}:
233      u32_np(f, U32.add(m, 1), U32.is_zero(U32.add(m, 1)), NB.is_prime(U32.to_nat(U32.add(m, 1))))

Uses (8)

Used by (3)