F32.hypot: def of Base Import: import Base Lines 1875-1889 of Base/base.bend: https://jend.leeeet.dev/read.txt?path=Base/base.bend&start_line=1875&end_line=1889 import Base # Outside [2^-60, 2^60] the squares would overflow or underflow, so scale # both sides by a power of two first; inside, the scale is 1 and exact. def F32.hypot(a: F32, b: F32) -> F32: +x = F32.abs(a) +y = F32.abs(b) +m = F32.max(x, y) +hi = F32.is_gt(m, 1.152921504606847e18) +lo = F32.is_lt(m, 8.673617379884035e-19) +s = Bool.pick(F32, hi, 8.470329472543003e-22, Bool.pick(F32, lo, 1.2676506002282294e30, 1.0)) +u = Bool.pick(F32, hi, 1.1805916207174113e21, Bool.pick(F32, lo, 7.888609052210118e-31, 1.0)) +p = F32.mul(x, s) +q = F32.mul(y, s) F32.mul(F32.sqrt(F32.add(F32.mul(p, p), F32.mul(q, q))), u) Uses (9): https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Bool.pick https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=F32 https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=F32.abs https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=F32.add https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=F32.is_gt https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=F32.is_lt https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=F32.max https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=F32.mul https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=F32.sqrt