tests/testthat/test-utils-numeric.R

test_that("log1mexp computes accurately for small and large values", {
  expect_equal(log1mexp(100), log1p(-exp(-100)), tolerance = 1e-10)
  expect_equal(log1mexp(0.1), log(-expm1(-0.1)), tolerance = 1e-10)
  expect_equal(log1mexp(0), -Inf)
  expect_equal(log1mexp(-1), -Inf)
})

test_that("log1pexp computes accurately", {
  expect_equal(log1pexp(0), log(2))
  expect_equal(log1pexp(50), 50, tolerance = 1e-10)
  expect_equal(log1pexp(-50), exp(-50), tolerance = 1e-10)
})

test_that("log_sum_exp matches log(exp(a) + exp(b))", {
  a <- 2.5
  b <- 3.1
  expect_equal(log_sum_exp(a, b), log(exp(a) + exp(b)), tolerance = 1e-10)
  expect_equal(log_sum_exp(1000, 1000), 1000 + log(2), tolerance = 1e-10)
})

test_that("safe_exp and safe_pow work without error/overflow", {
  expect_true(is.finite(safe_exp(1000)))
  expect_true(is.finite(safe_pow(0.5, 10)))
})

Try the MultiFrailty package in your browser

Any scripts or data that you put into this service are public.

MultiFrailty documentation built on Aug. 8, 2026, 1:07 a.m.