R/ks_c_cdf.R

Defines functions ks_c_cdf

Documented in ks_c_cdf

############################################################
## Direct boundary interface for the one-sample Exact-KS-FFT method

ks_c_cdf <- function(n, A, B)
{
  if (length(n) != 1L || !is.numeric(n) || is.na(n) || !is.finite(n) ||
      n <= 0 || n != floor(n)) {
    stop("'n' must be a positive integer")
  }

  if (!is.numeric(A) || !is.numeric(B)) {
    stop("'A' and 'B' must be numeric vectors")
  }

  if (length(A) != n || length(B) != n) {
    stop("'A' and 'B' must both have length 'n'")
  }

  ## Elementwise validation (finite values, range and monotonicity) and
  ## first-crossing detection are combined in one C++ pass.
  ##
  ## Preserve the historical internal boundary ordering:
  ## upper boundary B first, lower boundary A second.
  ans <- .ks_c_cdf_direct(n, B, A)

  if (ans$crossing >= 0L) {
    warning(
      sprintf(
        "The lower and upper boundaries cross! i=%d.",
        ans$crossing
      ),
      call. = FALSE
    )
  }

  ans$value
}

Try the KSgeneral package in your browser

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

KSgeneral documentation built on Aug. 23, 2026, 9:07 a.m.