tricu

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

50249f72bb4d09be1c1c1ab0a9f94b16a3e48cd5e998bc7fe6a0965126035210.tri (782B)


      1 -- Pure binary64 implementation; trusted internal helpers.
      2 !import native_math as N
      3 !import binary64_kernels as K
      4 !import binary64_layouts as L
      5 !import binary64_fast as F
      6 !export attach
      7 !export dominates
      8 !export exponent
      9 !export signBit
     10 !export subnormal
     11 
     12 exponent bits = L.low11 (L.drop52 bits)
     13 signBit bits = N.odd (L.drop11 (L.drop52 bits))
     14 subnormal fraction = K.lazy (_ : t 1230 0)
     15   (_ : let pad = N.subtract 53 (K.width fraction) in
     16     t (N.subtract 1230 pad) (F.shiftSelective pad fraction)) (N.zero fraction)
     17 scale d = K.head (K.tail d)
     18 mant d = K.tail (K.tail d)
     19 attach negative bits = K.choose (F.pack (N.add 2048 (L.drop52 bits)) bits) bits negative
     20 dominates a b = K.either (N.gt (scale a) (scale b))
     21   (K.both (N.equal (scale a) (scale b)) (N.gte (mant a) (mant b)))