safe_divide: Safe Division Function Handling Zeros, Singularity, and...

View source: R/validation.R

safe_divideR Documentation

Safe Division Function Handling Zeros, Singularity, and Non-Finite Values

Description

Performs division with protection against division by zero, near-zero denominator singularities ($|den| < tol$), and non-finite values (Inf, -Inf, NaN), replacing invalid results with NA.

Usage

safe_divide(num, den, tol = 1e-06)

Arguments

num

Numerator (SpatRaster or numeric).

den

Denominator (SpatRaster or numeric).

tol

Singularity tolerance threshold. Values with $|den| < tol$ are safely converted to NA. Defaults to 1e-6.

Value

An object of the same class as inputs with values safely bounded and non-finite values replaced by NA.


GeoIndexR documentation built on Oct. 10, 2026, 5:08 p.m.