~/bend-docscommunity

fb.bend checks

raw source on the hub · import bend-float64@0.1.7.0/fb.bend as Fb

bend-float64's fast balls: (-1)^neg * m * 2^e with |true value - that| <= err * 2^e, m a 128-bit integer with its top bit set (or 0), err a count of units of 2^e that every operation updates, rounding up. A count from 2^30 up marks a failed ball, and every operation keeps it failed. The same idea as ball.bend at a fixed 128 bits: no lists, so a few hundred native word operations per step. An error count past 2^30 means the ball has lost the precision to answer; decide then answers nothing and the caller falls back to the arbitrary-precision balls. Pure.

3 imports
import Base
import ./wide.bend as W
import ./float64.bend as F

Types

type FB source · line 11 · raw

Data

type RS source · line 228 · raw

Data

|a - b| <= n 2^e for two positive balls of about the same size (exponents at most 1 apart), without normalizing the small difference (which would make its error count overflow): n counts the midpoints' difference and both errors

Definitions

def sat source · line 14 · raw

U32

def is_neg source · line 17 · raw

@+x:U32 -> Bool

def s_lt source · line 20 · raw

@+a:U32 -> @+b:U32 -> Bool

def lost source · line 24 · raw

@+x:U32 -> Bool

an error count from 2^30 up means the ball has failed: it stays failed through every operation

def sadd source · line 28 · raw

@+a:U32 -> @+b:U32 -> U32

a + b, stuck at 2^31 once either is failed

def ceil_down source · line 32 · raw

@+x:U32 -> @+d:U32 -> U32

ceil(x / 2^d), d >= 0

def scale_up source · line 36 · raw

@+x:U32 -> @+k:U32 -> U32

ceil(x * 2^k) for a signed k, stuck at 2^31

def halve source · line 41 · raw

@+v:U32 -> U32

def zero128 source · line 44 · raw

0xf7ad0261e36ff1404423df221623a9ba/wide.W128

def fail source · line 47 · raw

FB

def top32 source · line 50 · raw

@m:0xf7ad0261e36ff1404423df221623a9ba/wide.W128 -> U32

def is_zero source · line 53 · raw

@m:0xf7ad0261e36ff1404423df221623a9ba/wide.W128 -> Bool

def norm source · line 57 · raw

@+neg:Bool -> @+m:0xf7ad0261e36ff1404423df221623a9ba/wide.W128 -> @+e:U32 -> @+err:U32 -> FB

m * 2^e with m shifted until its top bit is set (err scaled with it)

def of_cls source · line 62 · raw

@c:0xf7ad0261e36ff1404423df221623a9ba/float64.Cls -> FB

a finite float64, exactly

def of_f64 source · line 71 · raw

@x:0xf7ad0261e36ff1404423df221623a9ba/float64.F64 -> FB

def of_u32 source · line 74 · raw

@+n:U32 -> FB

def one source · line 77 · raw

FB

def neg source · line 80 · raw

@a:FB -> FB

def abs source · line 85 · raw

@a:FB -> FB

def with_neg source · line 90 · raw

@+n:Bool -> @a:FB -> FB

def neg_of source · line 95 · raw

@a:FB -> Bool

def exp_of source · line 100 · raw

@a:FB -> U32

def err_of source · line 105 · raw

@a:FB -> U32

def mid_of source · line 110 · raw

@a:FB -> 0xf7ad0261e36ff1404423df221623a9ba/wide.W128

def mul_pow2 source · line 115 · raw

@a:FB -> @+k:U32 -> FB

def widen source · line 120 · raw

@a:FB -> @+x:U32 -> FB

def top source · line 126 · raw

@a:FB -> U32

the exponent of the top bit plus one (a's magnitude is below 2^top); very low for 0

def err_to source · line 132 · raw

@+err:U32 -> @+from:U32 -> @+to:U32 -> U32

err units of 2^from as units of 2^to, rounded up

def mul_go source · line 138 · raw

@+neg:Bool -> @+p:0xf7ad0261e36ff1404423df221623a9ba/wide.W128 -> @+e:U32 -> @+tz:U32 -> @+ca:U32 -> @+cb:U32 -> @+cab:U32 -> FB

p = floor(ma mb / 2^128); exact when the factors' trailing zeros reach 128 (the low half of the product is 0)

def cross source · line 144 · raw

@+ta:U32 -> @+eb:U32 -> U32

a's top word times eb, over 2^32, rounded up (the part of a b's error that comes from b's)

def mul source · line 148 · raw

@a:FB -> @b:FB -> FB

a * b

def mul_u source · line 155 · raw

@a:FB -> @+n:U32 -> FB

def sqr source · line 158 · raw

@+a:FB -> FB

def add_same source · line 163 · raw

@+n:Bool -> @+a:0xf7ad0261e36ff1404423df221623a9ba/wide.W128 -> @+b:0xf7ad0261e36ff1404423df221623a9ba/wide.W128 -> @+e:U32 -> @+r:U32 -> FB

def add_diff source · line 168 · raw

@+na:Bool -> @+a:0xf7ad0261e36ff1404423df221623a9ba/wide.W128 -> @+nb:Bool -> @+b:0xf7ad0261e36ff1404423df221623a9ba/wide.W128 -> @+e:U32 -> @+r:U32 -> FB

def add_sign source · line 172 · raw

@diff:Bool -> @+nx:Bool -> @+mx:0xf7ad0261e36ff1404423df221623a9ba/wide.W128 -> @+ny:Bool -> @+ys:0xf7ad0261e36ff1404423df221623a9ba/wide.W128 -> @+e:U32 -> @+r:U32 -> FB

def add_al source · line 180 · raw

@+nx:Bool -> @+mx:0xf7ad0261e36ff1404423df221623a9ba/wide.W128 -> @+ex:U32 -> @+rx:U32 -> @+ny:Bool -> @+my:0xf7ad0261e36ff1404423df221623a9ba/wide.W128 -> @+ey:U32 -> @+ry:U32 -> FB

x the larger exponent: y's mantissa shifted down to x's units (a unit more error when a set bit is shifted out)

def add_ord source · line 184 · raw

@swap:Bool -> @+na:Bool -> @+ma:0xf7ad0261e36ff1404423df221623a9ba/wide.W128 -> @+ea:U32 -> @+ra:U32 -> @+nb:Bool -> @+mb:0xf7ad0261e36ff1404423df221623a9ba/wide.W128 -> @+eb:U32 -> @+rb:U32 -> FB

def add_go source · line 191 · raw

@a:FB -> @b:FB -> FB

def add_z source · line 196 · raw

@za:Bool -> @zb:Bool -> @+a:FB -> @+b:FB -> FB

def add source · line 208 · raw

@+a:FB -> @+b:FB -> FB

a + b

def sub source · line 212 · raw

@+a:FB -> @b:FB -> FB

a - b

def mid source · line 217 · raw

@a:FB -> FB

def mant_f64 source · line 223 · raw

@+m:0xf7ad0261e36ff1404423df221623a9ba/wide.W128 -> 0xf7ad0261e36ff1404423df221623a9ba/float64.F64

m / 2^127 as a float64 in [1, 2) (its top 53 bits)

def resid_go source · line 231 · raw

@+mh:0xf7ad0261e36ff1404423df221623a9ba/wide.W128 -> @+eh:U32 -> @+rh:U32 -> @+ml:0xf7ad0261e36ff1404423df221623a9ba/wide.W128 -> @+el:U32 -> @+rl:U32 -> RS

def resid source · line 238 · raw

@a:FB -> @b:FB -> RS

def resid_units source · line 244 · raw

@r:RS -> @+k:U32 -> U32

ceil(n 2^(e + k) (1 + 2^-8))

def recip_step source · line 249 · raw

@+b:FB -> @+r:FB -> FB

def div_go source · line 252 · raw

@+a:FB -> @+b:FB -> FB

def div source · line 260 · raw

@+a:FB -> @+b:FB -> FB

a / b, b's ball away from 0 (else a failed ball)

def rsqrt_step source · line 263 · raw

@+x:FB -> @+r:FB -> FB

def sqrt_go source · line 266 · raw

@+x:FB -> FB

def sqrt source · line 277 · raw

@+x:FB -> FB

sqrt(x), x's ball positive (else a failed ball)

def round_w_m source · line 284 · raw

@+rm:0xf7ad0261e36ff1404423df221623a9ba/float64.Rnd -> @+neg:Bool -> @w:0xf7ad0261e36ff1404423df221623a9ba/wide.W128 -> @+e:U32 -> 0xf7ad0261e36ff1404423df221623a9ba/float64.F64

def round_w source · line 289 · raw

@+neg:Bool -> @w:0xf7ad0261e36ff1404423df221623a9ba/wide.W128 -> @+e:U32 -> 0xf7ad0261e36ff1404423df221623a9ba/float64.F64

def same source · line 292 · raw

@a:0xf7ad0261e36ff1404423df221623a9ba/float64.F64 -> @b:0xf7ad0261e36ff1404423df221623a9ba/float64.F64 -> Bool

def decide_go source · line 297 · raw

@+rm:0xf7ad0261e36ff1404423df221623a9ba/float64.Rnd -> @+n:Bool -> @+m:0xf7ad0261e36ff1404423df221623a9ba/wide.W128 -> @+e:U32 -> @+r:U32 -> Maybe<&2, 0xf7ad0261e36ff1404423df221623a9ba/float64.F64>

def decide_m source · line 303 · raw

@+rm:0xf7ad0261e36ff1404423df221623a9ba/float64.Rnd -> @a:FB -> Maybe<&2, 0xf7ad0261e36ff1404423df221623a9ba/float64.F64>

the float64 every point of the ball rounds to in mode rm, when they all round to the same one

def decide source · line 309 · raw

@a:FB -> Maybe<&2, 0xf7ad0261e36ff1404423df221623a9ba/float64.F64>

the float64 every point of the ball rounds to (to nearest), when they all round to the same one