def beta_ok

bendtorch@1.3.0.0 · main.bend:514

import bendtorch@1.3.0.0/main.bend as Bendtorch
import Base

514# c = 1 - b up to F32's rounding, with 0 < c <= 1 (PyTorch's 0 <= beta < 1). For b in [0, 1), 1 - b taken in F32 is
515# within half an ulp of the exact value and c's own rounding adds at most as much, so a c written as 1 - b is always
516# under 2^-23 from it, while a typo (0.01 for 0.001, c1 and c2 swapped) is far above. A NaN fails every comparison.
517def beta_ok(+b: F32, +c: F32) -> Bool:
518  +d = ((1.0 - b : F32) - c : F32)
519  Bool.and(Bool.and((c > 0.0 : F32), (c <= 1.0 : F32)), ((d * d : F32) <= 0.0000000000000142108547152020037174224853515625 : F32))

Uses (7)

Used by (1)