def sigmoid_reduced

stelliferous@0.0.2.0 · math_fp32.bend:53

import stelliferous@0.0.2.0/math_fp32.bend as MathFp32
import Base

53# u=-value, n approximates u/ln(2) to the nearest integer, r=u-n*ln(2).
54# The exponent word makes
55# H=2^(64-n), so sigmoid(x)=H/(exp(r)+2^-n)*2^-64. H remains normal;
56# only the last multiplication underflows. The tiny denominator addend q
57# may be floored to the least normal F32 without changing its rounded sum.
58def sigmoid_reduced(silu: Bool,x: F32,+value: F32,+biased: F32) -> F32:
59  +n = (biased - 12582912.0 : F32)
60  +r = ((n * F32.neg(0.693359375) - value : F32) + n * 0.00021219444005469058 : F32)
61  +power = from_bits((1602224128 - U32.shln(F32.bits(biased),23n) : U32))
62  +q = from_bits((U32.max(F32.bits(power),545259520) - 536870912 : U32))
63  logistic_scaled(silu,x,value,power,logistic_denominator(q,(1.0 + q : F32),r,exponential_remainder(r)))

Uses (15)

Used by (1)