Learn R Programming

fb4package (version 2.0.0)

safe_exp: Safe exponential

Description

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")

Value

exp(x), or exp(max_exp) for values that would overflow

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

Examples

Run this code
safe_exp(1)
suppressWarnings(safe_exp(1000))
suppressWarnings(safe_exp(-1000))

Run the code above in your browser using DataLab