Computes exp(x) with protection against overflow. Values above
max_exp are clamped before exponentiation to avoid Inf.
Usage
safe_exp(x, max_exp = 700, warn = TRUE, param_name = "exponent")
Arguments
- x
Numeric value or vector
- max_exp
Maximum allowed exponent, default 700
- warn
Logical; issue a warning when clamping occurs, default TRUE
- param_name
Name used in warning messages
Value
exp(x), or exp(max_exp) for values that would overflow
Examples
if (FALSE) { # \dontrun{
safe_exp(1) # exp(1)
safe_exp(1000) # exp(700) with warning
safe_exp(-1000) # exp(-700) with warning
} # }