cells64.bend checks
raw source on the hub · import bend-ndarray@0.1.4.0/cells64.bend as Cells64
bend-ndarray's float64 elements, computed with bend-float64 (IEEE 754 binary64 in pure Bend, x86-64's bits). A float64 element is two cells in the tree, its high word then its low one (tree.bend). Arithmetic and comparisons are IEEE's; floor_divide and remainder follow NumPy's divmod (Python's // and %); the math functions are bend-float64's, correctly rounded.
7 imports
import Base import ./shape.bend as S import ./cells.bend as C import bend-float64@0.1.8.0/wide.bend as W import bend-float64@0.1.8.0/float64.bend as F import bend-float64@0.1.8.0/math.bend as M import bend-float64@0.1.8.0/text.bend as T
Types
type NM source · line 32 · raw
Data
m (nonzero) shifted until its top bit is bit 52, and its exponent lowered to match
NM@e:U32 -> @m:0x72aa159312099184b98e33378b057a0a/wide.W64 -> NM
type FK source · line 73 · raw
Data
which way fmod goes: invalid (a NaN, an infinite x, a zero y), x itself (|x| < |y|, or y infinite), or the exact loop
FBothNanFK
FInvalidFK
FKeepFK
FLoopFK
type DM source · line 105 · raw
Data
DM@div:0x72aa159312099184b98e33378b057a0a/float64.F64 -> @mod:0x72aa159312099184b98e33378b057a0a/float64.F64 -> DM
Definitions
def is_f64 source · line 13 · raw
@dt:0xb394b5997edb05025e33977930018c47/shape.DType -> Bool
def of source · line 20 · raw
@+h:U32 -> @+l:U32 -> 0x72aa159312099184b98e33378b057a0a/float64.F64
def zero source · line 23 · raw
0x72aa159312099184b98e33378b057a0a/float64.F64
def one source · line 26 · raw
0x72aa159312099184b98e33378b057a0a/float64.F64
def norm source · line 35 · raw
@+e:U32 -> @+m:0x72aa159312099184b98e33378b057a0a/wide.W64 -> NM
def nm_of source · line 39 · raw
@c:0x72aa159312099184b98e33378b057a0a/float64.Cls -> NM
def mod_steps source · line 47 · raw
@k:Nat -> @+r:0x72aa159312099184b98e33378b057a0a/wide.W64 -> @+my:0x72aa159312099184b98e33378b057a0a/wide.W64 -> 0x72aa159312099184b98e33378b057a0a/wide.W64
r 2^k mod my, k steps of doubling, r < my
def scaled source · line 57 · raw
@+neg:Bool -> @+r:0x72aa159312099184b98e33378b057a0a/wide.W64 -> @+e:U32 -> 0x72aa159312099184b98e33378b057a0a/float64.F64
r 2^(e - 1075) with x's sign, exactly (r < 2^53; e from -51 up, below 1 for a subnormal y): one product by a power of two from e = 53 up, else by 2^(e - 965) and then 2^-110, every step exact because the result is a float64
def fmod_nm source · line 62 · raw
@a:NM -> @b:NM -> @+neg:Bool -> 0x72aa159312099184b98e33378b057a0a/float64.F64
def fmod_big source · line 69 · raw
@+x:0x72aa159312099184b98e33378b057a0a/float64.F64 -> @+y:0x72aa159312099184b98e33378b057a0a/float64.F64 -> 0x72aa159312099184b98e33378b057a0a/float64.F64
|x| >= |y|, both finite and nonzero
def nan_pick source · line 81 · raw
@+x:0x72aa159312099184b98e33378b057a0a/float64.F64 -> @+y:0x72aa159312099184b98e33378b057a0a/float64.F64 -> 0x72aa159312099184b98e33378b057a0a/float64.F64
of two NaNs, quieted, the one with the larger significand, the positive one of two equal (glibc's fmod on x86-64, whose NaN NumPy's remainder returns)
def fmod_k source · line 88 · raw
@k:FK -> @+x:0x72aa159312099184b98e33378b057a0a/float64.F64 -> @+y:0x72aa159312099184b98e33378b057a0a/float64.F64 -> 0x72aa159312099184b98e33378b057a0a/float64.F64
def fmod source · line 101 · raw
@+x:0x72aa159312099184b98e33378b057a0a/float64.F64 -> @+y:0x72aa159312099184b98e33378b057a0a/float64.F64 -> 0x72aa159312099184b98e33378b057a0a/float64.F64
C's fmod: x - trunc(x / y) y, exactly, with x's sign; a NaN, an infinite x or a zero y gives (x y) / (x y), as glibc (and of two NaNs, nan_pick's)
def dm_floor source · line 108 · raw
@+div:0x72aa159312099184b98e33378b057a0a/float64.F64 -> @+mod:0x72aa159312099184b98e33378b057a0a/float64.F64 -> @+x:0x72aa159312099184b98e33378b057a0a/float64.F64 -> @+y:0x72aa159312099184b98e33378b057a0a/float64.F64 -> DM
def dm_adjust source · line 112 · raw
@+mod:0x72aa159312099184b98e33378b057a0a/float64.F64 -> @+div:0x72aa159312099184b98e33378b057a0a/float64.F64 -> @+x:0x72aa159312099184b98e33378b057a0a/float64.F64 -> @+y:0x72aa159312099184b98e33378b057a0a/float64.F64 -> DM
def dm_go source · line 117 · raw
@by0:Bool -> @+mod:0x72aa159312099184b98e33378b057a0a/float64.F64 -> @+x:0x72aa159312099184b98e33378b057a0a/float64.F64 -> @+y:0x72aa159312099184b98e33378b057a0a/float64.F64 -> DM
def divmod source · line 125 · raw
@+x:0x72aa159312099184b98e33378b057a0a/float64.F64 -> @+y:0x72aa159312099184b98e33378b057a0a/float64.F64 -> DM
NumPy's divmod for floats (npy_divmod): Python's // and %, the quotient snapped to an integer
def dm_div source · line 128 · raw
@d:DM -> 0x72aa159312099184b98e33378b057a0a/float64.F64
def dm_mod source · line 133 · raw
@d:DM -> 0x72aa159312099184b98e33378b057a0a/float64.F64
def f2 source · line 141 · raw
@op:0xb394b5997edb05025e33977930018c47/cells.B2 -> @+x:0x72aa159312099184b98e33378b057a0a/float64.F64 -> @+y:0x72aa159312099184b98e33378b057a0a/float64.F64 -> 0x72aa159312099184b98e33378b057a0a/float64.F64
an arithmetic operation (not a comparison)
def cmp2 source · line 169 · raw
@op:0xb394b5997edb05025e33977930018c47/cells.B2 -> @+x:0x72aa159312099184b98e33378b057a0a/float64.F64 -> @+y:0x72aa159312099184b98e33378b057a0a/float64.F64 -> U32
a comparison, as a bool cell
def math source · line 188 · raw
@f:0xb394b5997edb05025e33977930018c47/cells.MF -> @+x:0x72aa159312099184b98e33378b057a0a/float64.F64 -> 0x72aa159312099184b98e33378b057a0a/float64.F64
def sign source · line 230 · raw
@+x:0x72aa159312099184b98e33378b057a0a/float64.F64 -> 0x72aa159312099184b98e33378b057a0a/float64.F64
-1, 0 or 1 (nan stays nan; a zero of either sign gives +0, as NumPy)
def cell1 source · line 234 · raw
@op:0xb394b5997edb05025e33977930018c47/cells.U1 -> @+x:0x72aa159312099184b98e33378b057a0a/float64.F64 -> 0x72aa159312099184b98e33378b057a0a/float64.F64
a float64 to another float64 (every operation but a conversion to another dtype)
def to_cell source · line 255 · raw
@to:0xb394b5997edb05025e33977930018c47/shape.DType -> @+x:0x72aa159312099184b98e33378b057a0a/float64.F64 -> U32
a float64 to another dtype's cell: float32 rounded to nearest; int32 toward zero (nan and out of range: -2^31, as x86); uint32 through int64, as NumPy on x86-64; uint8 the low byte of the int32; bool: not zero
def of_cell source · line 271 · raw
@from:0xb394b5997edb05025e33977930018c47/shape.DType -> @+x:U32 -> 0x72aa159312099184b98e33378b057a0a/float64.F64
another dtype's cell to a float64, exactly
def show source · line 281 · raw
@+x:0x72aa159312099184b98e33378b057a0a/float64.F64 -> String
an element as NumPy's repr writes it (Python's repr of the float)