def tanh_magnitude

stelliferous@0.0.2.0 · math_fp32.bend:89

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

89# At |x|>=10, 1-tanh(|x|)<2*exp(-20)<2^-25. Clamping before arithmetic
90# also keeps infinities away from intermediate products; NaNs propagate.
91def tanh_magnitude(+x: F32) -> F32:
92  F32.max(F32.min(10.0,from_bits(U32.and(F32.bits(x),2147483647))),0.000244140625)

Uses (6)

Used by (1)