Skip to main content

Module logsumexp

Module logsumexp 

Source
Expand description

Overflow-safe log(cosh(x)) and log(exp(x) + exp(y)).

Pure-Rust port of limma’s logsumexp.R (logcosh and logsumexp). Both avoid floating overflow/underflow: logcosh uses a small-x Taylor term and a large-x linear tail, and logsumexp reduces to logcosh of the half-difference.

Functions§

logcosh
logcosh(x): log(cosh(x)) without overflow. Uses 0.5*x^2 for very small |x| and the asymptote |x| - log 2 for |x| >= 17.
logsumexp
logsumexp(x, y): log(exp(x) + exp(y)) without overflow or underflow. Propagates NaN; +Inf in either argument gives +Inf; -Inf is the identity element.