~/bend-docscommunity

fast.bend checks

raw source on the hub · import bend-float64@0.1.8.0/fast.bend as Fast

bend-float64's fast path for the math functions: the same evaluations as math.bend's, on 128-bit fast balls (fb.bend) with tables (fbconsts.bend), so one call costs a few microseconds. Every rounding error is counted by the balls themselves, and each polynomial adds its own truncation bound, so a ball that decides is the correctly rounded answer; one that cannot (a hard case, heavy cancellation) sends the caller to the arbitrary-precision path. Pure.

5 imports
import Base
import ./wide.bend as W
import ./float64.bend as F
import ./fb.bend as Q
import ./fbconsts.bend as C

Types

type TQ source · line 107 · raw

Data

type R4 source · line 159 · raw

Data

256-bit numbers as four 64-bit words, the top first

type KF source · line 189 · raw

Data

|x| 2/pi as a quadrant k (mod 4) and the fraction left, as a ball: |x| = k pi/2 + f pi/2, |f| <= 1/2

Definitions

def is_neg source · line 12 · raw

@+x:U32 -> Bool

def approx source · line 16 · raw

@a:0x72aa159312099184b98e33378b057a0a/fb.FB -> 0x72aa159312099184b98e33378b057a0a/float64.F64

the float64 nearest the ball's midpoint, ignoring its error (for choosing branches, never for answers)

def of_i32 source · line 21 · raw

@+k:U32 -> 0x72aa159312099184b98e33378b057a0a/fb.FB

def signed source · line 24 · raw

@+neg:Bool -> @+a:0x72aa159312099184b98e33378b057a0a/fb.FB -> 0x72aa159312099184b98e33378b057a0a/fb.FB

def below source · line 28 · raw

@+a:0x72aa159312099184b98e33378b057a0a/fb.FB -> @+k:U32 -> Bool

|a| below 2^k, judged on the midpoint

def exp_go source · line 33 · raw

@+a:0x72aa159312099184b98e33378b057a0a/fb.FB -> 0x72aa159312099184b98e33378b057a0a/fb.FB

def exp_big source · line 40 · raw

@huge:Bool -> @+a:0x72aa159312099184b98e33378b057a0a/fb.FB -> 0x72aa159312099184b98e33378b057a0a/fb.FB

def exp source · line 48 · raw

@+a:0x72aa159312099184b98e33378b057a0a/fb.FB -> 0x72aa159312099184b98e33378b057a0a/fb.FB

e^a; past |a| = 1500 every point overflows or underflows, so a power of two far out stands for them all

def expm1_go source · line 51 · raw

@near:Bool -> @+a:0x72aa159312099184b98e33378b057a0a/fb.FB -> 0x72aa159312099184b98e33378b057a0a/fb.FB

def expm1 source · line 59 · raw

@+a:0x72aa159312099184b98e33378b057a0a/fb.FB -> 0x72aa159312099184b98e33378b057a0a/fb.FB

e^a - 1 (the series below 2^-7, exact near 0)

def log1p_small source · line 64 · raw

@+t:0x72aa159312099184b98e33378b057a0a/fb.FB -> 0x72aa159312099184b98e33378b057a0a/fb.FB

def log_tab_go source · line 67 · raw

@t:0x72aa159312099184b98e33378b057a0a/fbconsts.LogT -> @+mant:0x72aa159312099184b98e33378b057a0a/fb.FB -> @+e:U32 -> 0x72aa159312099184b98e33378b057a0a/fb.FB

def log_far source · line 72 · raw

@+v:0x72aa159312099184b98e33378b057a0a/fb.FB -> 0x72aa159312099184b98e33378b057a0a/fb.FB

def log_go source · line 77 · raw

@near:Bool -> @+v:0x72aa159312099184b98e33378b057a0a/fb.FB -> 0x72aa159312099184b98e33378b057a0a/fb.FB

def log source · line 85 · raw

@+v:0x72aa159312099184b98e33378b057a0a/fb.FB -> 0x72aa159312099184b98e33378b057a0a/fb.FB

log v, v > 0 (near 1, the series of v - 1, exact)

def log1p_go source · line 88 · raw

@near:Bool -> @+u:0x72aa159312099184b98e33378b057a0a/fb.FB -> 0x72aa159312099184b98e33378b057a0a/fb.FB

def log1p source · line 96 · raw

@+u:0x72aa159312099184b98e33378b057a0a/fb.FB -> 0x72aa159312099184b98e33378b057a0a/fb.FB

log(1 + u) (the series below 2^-8, exact near 0)

def sin_r source · line 101 · raw

@+r:0x72aa159312099184b98e33378b057a0a/fb.FB -> 0x72aa159312099184b98e33378b057a0a/fb.FB

def cos_r source · line 104 · raw

@+r:0x72aa159312099184b98e33378b057a0a/fb.FB -> 0x72aa159312099184b98e33378b057a0a/fb.FB

def tq source · line 113 · raw

@t:TQ -> @+r:0x72aa159312099184b98e33378b057a0a/fb.FB -> 0x72aa159312099184b98e33378b057a0a/fb.FB

def trig_kr source · line 125 · raw

@+which:U32 -> @+k:U32 -> @+r:0x72aa159312099184b98e33378b057a0a/fb.FB -> 0x72aa159312099184b98e33378b057a0a/fb.FB

k's quadrant (k mod 4) and the reduced argument r, |r| <= pi/4: sin, cos (which 0, 1) or tan (2) of k pi/2 + r

def trig_go source · line 133 · raw

@+which:U32 -> @+x:0x72aa159312099184b98e33378b057a0a/float64.F64 -> 0x72aa159312099184b98e33378b057a0a/fb.FB

|x| below 2^30: k = x 2/pi rounded, r = x - k pi/2 with pi/2 in three parts (the first two exact)

def funnel source · line 144 · raw

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

bits of a then b: a shifted up by sh (0 .. 31), b's top bits below

def pair source · line 147 · raw

@+a:U32 -> @+b:U32 -> @+c:U32 -> @+sh:U32 -> 0x72aa159312099184b98e33378b057a0a/wide.W64

def or128 source · line 150 · raw

@a:0x72aa159312099184b98e33378b057a0a/wide.W128 -> @b:0x72aa159312099184b98e33378b057a0a/wide.W128 -> 0x72aa159312099184b98e33378b057a0a/wide.W128

def lo_of source · line 155 · raw

@+x:0x72aa159312099184b98e33378b057a0a/wide.W64 -> 0x72aa159312099184b98e33378b057a0a/wide.W128

def mul_win source · line 163 · raw

@+m:0x72aa159312099184b98e33378b057a0a/wide.W64 -> @t:R4 -> R4

m T mod 2^256

def window source · line 177 · raw

@+e:U32 -> R4

with x = m 2^(e - 1075), the window T: its top bit is bit tb = 3601 - (e - 1075) of floor(2/pi 2^3600) (C.tpi_word), bit tb mod 32 of word tb / 32, so T's words are those from there down, shifted up by sh

def big_frac source · line 195 · raw

@r:R4 -> KF

the quadrant from bits 254-255 of m T, the fraction f from the 254 below (as f - 1, the next quadrant, from 1/2 up), normalized to 128 bits: units of 2^(-126 - n) after n leading zeros, 1 for the bits cut and 2^(n - 75) for the window's end. A fraction under 2^-126 (none is, for a float64) fails the ball.

def far_c source · line 209 · raw

@c:0x72aa159312099184b98e33378b057a0a/float64.Cls -> KF

|x| 2/pi reduced, for |x| from 2^30 up

def far source · line 216 · raw

@x:0x72aa159312099184b98e33378b057a0a/float64.F64 -> KF

def trig_kf source · line 219 · raw

@r:KF -> @+which:U32 -> @+xneg:Bool -> 0x72aa159312099184b98e33378b057a0a/fb.FB

def trig_big source · line 224 · raw

@big:Bool -> @+which:U32 -> @+x:0x72aa159312099184b98e33378b057a0a/float64.F64 -> 0x72aa159312099184b98e33378b057a0a/fb.FB

def trig source · line 232 · raw

@+which:U32 -> @+x:0x72aa159312099184b98e33378b057a0a/float64.F64 -> 0x72aa159312099184b98e33378b057a0a/fb.FB

which: 0 sin, 1 cos, 2 tan (x finite and nonzero)

def atan_poly source · line 237 · raw

@+u:0x72aa159312099184b98e33378b057a0a/fb.FB -> 0x72aa159312099184b98e33378b057a0a/fb.FB

def atan_j source · line 240 · raw

@zero:Bool -> @+u:0x72aa159312099184b98e33378b057a0a/fb.FB -> @+j:U32 -> 0x72aa159312099184b98e33378b057a0a/fb.FB

def atan_small source · line 248 · raw

@+u:0x72aa159312099184b98e33378b057a0a/fb.FB -> 0x72aa159312099184b98e33378b057a0a/fb.FB

def atan_go source · line 252 · raw

@small:Bool -> @+u:0x72aa159312099184b98e33378b057a0a/fb.FB -> 0x72aa159312099184b98e33378b057a0a/fb.FB

def atan source · line 260 · raw

@+t:0x72aa159312099184b98e33378b057a0a/fb.FB -> 0x72aa159312099184b98e33378b057a0a/fb.FB

atan t, any t