def round_even

cswap-bend-cli@0.1.0.0 · tui/fmt.bend:52

import cswap-bend-cli@0.1.0.0/tui/fmt.bend as Fmt
import Base

52# Centi-percent (4750 = 47.5 %) to a whole percent, halves to even as Python's
53# `f"{pct:.0f}"` does.
54def round_even(+c: U32) -> U32:
55  sel.u(U32.is_lt((c % 100 : U32), 50), (c / 100 : U32),
56    sel.u(U32.is_gt((c % 100 : U32), 50), ((c / 100 : U32) + 1 : U32),
57      sel.u(U32.is_eq((((c / 100 : U32)) % 2 : U32), 0), (c / 100 : U32), ((c / 100 : U32) + 1 : U32))))

Uses (8)

Used by (2)