def shr

bend-lawful-stdlib@0.1.0.0 · src/float/bin.bend:199

import bend-lawful-stdlib@0.1.0.0/src/float/bin.bend as Bin
import Base

199# a / 2^k, with the last bit shifted out (round) and whether any bit
200# below it was set (sticky); r and s are the bits already shifted out
201def shr(k: Nat, a: Bin, r: Bool, s: Bool) -> Bin & Bool & Bool:
202  match k:
203    case 0n:
204      (a, r, s)
205    case 1n+j:
206      match a:
207        case BZ{}:
208          shr(j, BZ{}, False{}, Bool.or(r, s))
209        case B0{x}:
210          shr(j, x, False{}, Bool.or(r, s))
211        case B1{x}:
212          shr(j, x, True{}, Bool.or(r, s))

Uses (6)

Used by (2)