statcpp
C++17 Header-Only Statistics Library
Loading...
Searching...
No Matches
Namespaces | Functions | Variables
numerical_utils.hpp File Reference

Numerical utilities for precision and convergence. More...

#include <algorithm>
#include <cmath>
#include <iterator>
#include <limits>
#include <stdexcept>
Include dependency graph for numerical_utils.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  statcpp
 

Functions

bool statcpp::approx_equal (double a, double b, double rel_tol=default_rel_tol, double abs_tol=default_abs_tol)
 Check if two floating-point numbers are approximately equal.
 
bool statcpp::is_zero (double x, double tol=default_abs_tol)
 Check if a value is close to zero.
 
bool statcpp::is_finite (double x)
 Check if a value is finite (not infinity or NaN)
 
template<typename Iterator >
bool statcpp::all_finite (Iterator first, Iterator last)
 Check if all values in a range are finite.
 
bool statcpp::has_converged_abs (double x_new, double x_old, double tol=1e-6)
 Check for convergence based on absolute change.
 
bool statcpp::has_converged_rel (double x_new, double x_old, double tol=1e-6)
 Check for convergence based on relative change.
 
bool statcpp::has_converged (double x_new, double x_old, double abs_tol=1e-8, double rel_tol=1e-6)
 Check for convergence using combined absolute and relative criteria.
 
double statcpp::log1p_safe (double x)
 Safely compute log(1 + x) for small x.
 
double statcpp::expm1_safe (double x)
 Safely compute exp(x) - 1 for small x.
 
double statcpp::clamp (double x, double min_val, double max_val)
 Clamp a value to a range [min_val, max_val].
 
bool statcpp::in_range (double x, double min_val, double max_val)
 Check if a value is in range [min_val, max_val].
 
double statcpp::relative_error (double x, double x_ref)
 Compute the relative error between two values.
 
double statcpp::safe_divide (double numerator, double denominator, double default_value=std::numeric_limits< double >::quiet_NaN())
 Safe division with check for division by zero.
 
template<typename Iterator >
double statcpp::kahan_sum (Iterator first, Iterator last)
 Compute sum with Kahan summation algorithm.
 
template<typename Iterator , typename Proj >
double statcpp::kahan_sum (Iterator first, Iterator last, Proj proj)
 Compute sum with Kahan summation algorithm (with projection)
 
template<typename Iterator1 , typename Iterator2 >
bool statcpp::approx_equal_range (Iterator1 first1, Iterator1 last1, Iterator2 first2, Iterator2 last2, double rel_tol=default_rel_tol, double abs_tol=default_abs_tol)
 Check if two ranges are approximately equal element-wise.
 

Variables

constexpr double statcpp::epsilon = std::numeric_limits<double>::epsilon()
 Machine epsilon for double precision.
 
constexpr double statcpp::default_rel_tol = 1e-9
 Default relative tolerance for floating-point comparisons.
 
constexpr double statcpp::default_abs_tol = 1e-12
 Default absolute tolerance for floating-point comparisons.
 

Detailed Description

Numerical utilities for precision and convergence.

Definition in file numerical_utils.hpp.