tricu

A lazy functional language based on Tree Calculus
Log | Files | Refs | README | LICENSE

float-alignment.tri (1181B)


      1 -- Normalized-significand alignment benchmark.
      2 -- Preconditions: a,b in [2^52,2^53); gap >= 0; a >= b when subtracting at gap 0.
      3 -- Return (cut, (significand, inexact)) in the smaller operand's integer units.
      4 -- For gap <= 54 the exact intermediate has at most 107 bits.
      5 -- For gap >= 55 the smaller operand is strictly below half even the smaller
      6 -- spacing beneath a power of two. RNE therefore returns a at scale gap.
      7 -- The nonzero-input invariant determines inexact=True independently of b.
      8 !import native_math as N
      9 !import kernels as K
     10 !import pipelines as P
     11 !export *
     12 far gap a = t gap (t a (t t))
     13 add gap a b = K.lazy (_ : far gap a)
     14   (_ : P.finishL (N.add (P.shiftLeft gap a) b)) (N.gte gap 55)
     15 subtract gap a b = K.lazy (_ : far gap a)
     16   (_ : P.finishL (N.subtract (P.shiftLeft gap a) b)) (N.gte gap 55)
     17 addOne x = add (K.head x) (K.head (K.tail x)) (K.tail (K.tail x))
     18 subtractOne x = subtract (K.head x) (K.head (K.tail x)) (K.tail (K.tail x))
     19 adds xs = K.map addOne xs
     20 subtracts xs = K.map subtractOne xs
     21 spin x = spin x
     22 farAddDemand x = K.head (K.tail (add 55 4503599627370496 (spin x)))
     23 farSubtractDemand x = K.head (K.tail (subtract 55 4503599627370496 (spin x)))