~/bend-docscommunity

big.bend checks

raw source on the hub · import bend-float64@0.1.6.0/big.bend as Big

bend-float64's unbounded natural numbers, for exact decimal conversion: a list of U32 limbs, least significant first, with no zero limb at the top (0 is the empty list). Add, subtract, compare, multiply by a word or a power of ten, shift by bits, bit length, and the top 64 bits with a sticky bit for the rest. Pure.

2 imports
import Base
import ./wide.bend as W

Types

type Top source · line 219 · raw

Data

the top 64 bits of a nonzero xs as a W64 whose lowest bit also records whether any bit below them was set, and how far they were shifted down (0 when xs has 64 bits or fewer)

type QR source · line 255 · raw

Data

type DS source · line 280 · raw

Data

Definitions

def cons_trim source · line 9 · raw

@+x:U32 -> @t:List<&2, U32> -> List<&2, U32>

def trim source · line 17 · raw

@xs:List<&2, U32> -> List<&2, U32>

drop zero limbs at the top

def of_u32 source · line 24 · raw

@+x:U32 -> List<&2, U32>

def of_w64 source · line 27 · raw

@x:0x71d2c95108c3e65654506f5521343c81/wide.W64 -> List<&2, U32>

def is_zero source · line 32 · raw

@xs:List<&2, U32> -> Bool

def add_go source · line 41 · raw

@xs:List<&2, U32> -> @ys:List<&2, U32> -> @+c:U32 -> List<&2, U32>

def add source · line 56 · raw

@xs:List<&2, U32> -> @ys:List<&2, U32> -> List<&2, U32>

def sub_go source · line 59 · raw

@xs:List<&2, U32> -> @ys:List<&2, U32> -> @+b:U32 -> List<&2, U32>

def sub source · line 70 · raw

@xs:List<&2, U32> -> @ys:List<&2, U32> -> List<&2, U32>

xs - ys, for xs >= ys

def cmp_top source · line 73 · raw

@rest:Cmp -> @+x:U32 -> @+y:U32 -> Cmp

def cmp source · line 83 · raw

@xs:List<&2, U32> -> @ys:List<&2, U32> -> Cmp

compares limb by limb from the top (a missing limb counts as 0)

def lt source · line 94 · raw

@xs:List<&2, U32> -> @ys:List<&2, U32> -> Bool

def le source · line 97 · raw

@xs:List<&2, U32> -> @ys:List<&2, U32> -> Bool

def mul_small_go source · line 102 · raw

@xs:List<&2, U32> -> @+m:U32 -> @+c:U32 -> List<&2, U32>

def mul_small source · line 112 · raw

@xs:List<&2, U32> -> @+m:U32 -> List<&2, U32>

xs * m

def mul_pow10_go source · line 115 · raw

@n:Nat -> @+xs:List<&2, U32> -> List<&2, U32>

def pow10_small source · line 122 · raw

@+r:U32 -> U32

def mul_pow10 source · line 128 · raw

@xs:List<&2, U32> -> @+n:U32 -> List<&2, U32>

xs * 10^n

def pow10 source · line 131 · raw

@+n:U32 -> List<&2, U32>

def zeros source · line 136 · raw

@n:Nat -> @xs:List<&2, U32> -> List<&2, U32>

def shl_bits source · line 143 · raw

@xs:List<&2, U32> -> @+k:U32 -> @+c:U32 -> List<&2, U32>

def shl source · line 151 · raw

@xs:List<&2, U32> -> @+n:U32 -> List<&2, U32>

xs * 2^n

def drop source · line 154 · raw

@n:Nat -> @xs:List<&2, U32> -> List<&2, U32>

def take source · line 163 · raw

@n:Nat -> @xs:List<&2, U32> -> List<&2, U32>

def head0 source · line 172 · raw

@xs:List<&2, U32> -> U32

def shr_bits source · line 179 · raw

@xs:List<&2, U32> -> @+k:U32 -> List<&2, U32>

def shr source · line 187 · raw

@xs:List<&2, U32> -> @+n:U32 -> List<&2, U32>

xs / 2^n rounded down

def low_nonzero source · line 191 · raw

@+xs:List<&2, U32> -> @+n:U32 -> Bool

whether any of the n lowest bits of xs is set

def bitlen_go source · line 197 · raw

@xs:List<&2, U32> -> @+acc:U32 -> U32

def bitlen source · line 207 · raw

@xs:List<&2, U32> -> U32

the number of bits, 0 for 0

def w64_of source · line 210 · raw

@xs:List<&2, U32> -> 0x71d2c95108c3e65654506f5521343c81/wide.W64

def top64_at source · line 222 · raw

@+xs:List<&2, U32> -> @+k:U32 -> Top

def top64_go source · line 225 · raw

@long:Bool -> @+xs:List<&2, U32> -> @+n:U32 -> Top

def top64 source · line 232 · raw

@+xs:List<&2, U32> -> Top

def mul10 source · line 237 · raw

@+xs:List<&2, U32> -> List<&2, U32>

xs * 10, as xs * 8 + xs * 2, by doubling (additions only)

def mul_go source · line 244 · raw

@+xs:List<&2, U32> -> @ys:List<&2, U32> -> List<&2, U32>

def mul source · line 252 · raw

@+xs:List<&2, U32> -> @ys:List<&2, U32> -> List<&2, U32>

xs * ys

def divq_go source · line 259 · raw

@n:Nat -> @+i:U32 -> @+num:List<&2, U32> -> @+den:List<&2, U32> -> @+q:List<&2, U32> -> QR

n steps of binary long division, quotient bit i first

def divq_n source · line 268 · raw

@big:Bool -> @+num:List<&2, U32> -> @+den:List<&2, U32> -> @+n:U32 -> QR

def divq source · line 276 · raw

@+num:List<&2, U32> -> @+den:List<&2, U32> -> QR

num / den and num mod den, den nonzero

def div_small_go source · line 283 · raw

@xs:List<&2, U32> -> @+d:U32 -> @+r:U32 -> @+acc:List<&2, U32> -> DS

def div_small_q source · line 293 · raw

@x:DS -> DS

def div_small source · line 299 · raw

@xs:List<&2, U32> -> @+d:U32 -> DS

xs / d and xs mod d, for 0 < d < 2^16

def isqrt_go source · line 303 · raw

@n:Nat -> @+i:U32 -> @+x:List<&2, U32> -> @+q:List<&2, U32> -> QR

n steps of the bit-by-bit square root: root bit i first

def isqrt source · line 313 · raw

@+x:List<&2, U32> -> QR

floor(sqrt(x)) and x minus its square

def cube source · line 317 · raw

@+x:List<&2, U32> -> List<&2, U32>

def icbrt_go source · line 321 · raw

@n:Nat -> @+i:U32 -> @+x:List<&2, U32> -> @+q:List<&2, U32> -> List<&2, U32>

n steps of the bit-by-bit cube root: root bit i first

def icbrt source · line 330 · raw

@+x:List<&2, U32> -> List<&2, U32>

floor(cbrt(x))

def pow_go source · line 334 · raw

@n:Nat -> @+x:List<&2, U32> -> @+acc:List<&2, U32> -> List<&2, U32>

def pow source · line 342 · raw

@+x:List<&2, U32> -> @+n:U32 -> List<&2, U32>

x^n

def shr_small source · line 346 · raw

@xs:List<&2, U32> -> @+k:U32 -> List<&2, U32>

xs / 2^k rounded down, for 0 < k < 32 (no division of k: cheap for the checker)

def isq_step source · line 349 · raw

@ge:Bool -> @+x:List<&2, U32> -> @+res:List<&2, U32> -> @+bit:List<&2, U32> -> QR

def isq_go source · line 357 · raw

@n:Nat -> @+bit:List<&2, U32> -> @p:QR -> QR

the shift-by-two square root: res and x as QR, bit falling by 4 each step

def isqrt2 source · line 365 · raw

@+x:List<&2, U32> -> QR

floor(sqrt(x)) and x minus its square, shifting only by constants