MathFp32.logarithm_series: def of stelliferous@0.0.2.0 Import: import stelliferous@0.0.2.0/math_fp32.bend as MathFp32 Lines 146-166 of stelliferous@0.0.2.0/math_fp32.bend: https://jend.leeeet.dev/read.txt?path=stelliferous@0.0.2.0/math_fp32.bend&start_line=146&end_line=166 import Base # For s near r/(2+r), d = r-(2+r)*s gives the exact real identity # log(1+r) = 2*atanh(s) + log(1+d/(1+s)). The odd series ends at s^11. # Split r and s into 12-bit heads so their head product is exact; retain # the low products in d. (1-s)*(1+s^2+s^4) approximates 1/(1+s). # FastTwoSum retains the low bits when adding the exponent's ln(2) part. def logarithm_series(+r: F32,+n: F32) -> F32: +s = (r / (2.0 + r : F32) : F32) +square = (s * s : F32) +r_high = from_bits(U32.and(F32.bits(r),4294963200)) +r_low = (r - r_high : F32) +s_high = from_bits(U32.and(F32.bits(s),4294963200)) +s_low = (s - s_high : F32) +product_low = ((r_high * s_low + r_low * s_high : F32) + r_low * s_low : F32) +correction = (((r - 2.0 * s : F32) - r_high * s_high : F32) - product_low : F32) +p = ((((0.09090909090909091 * square + 0.1111111111111111 : F32) * square + 0.14285714285714285 : F32) * square + 0.2 : F32) * square + 0.3333333333333333 : F32) +main = (2.0 * s : F32) +rest = ((main * square : F32) * p + correction * ((1.0 - s : F32) * (1.0 + square * (1.0 + square : F32) : F32) : F32) : F32) +high = (n * 0.693359375 : F32) +sum = (high + main : F32) +tail = (main - (sum - high : F32) : F32) (sum + (rest + (n * F32.neg(0.000212194440) + tail : F32) : F32) : F32) Uses (9): https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=F32 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.bits https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=F32.div 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.neg https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=F32.sub https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32.and https://jend.leeeet.dev/definition.txt?path=stelliferous@0.0.2.0/math_fp32.bend&name=from_bits