From 932efe1a370e7a8c9f6c7a2dd0beddb36fb7a601 Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Fri, 7 May 2021 16:40:54 +0530 Subject: Add rtol? predicate. * src/utils.sc (rtol?): New function. * include/utils.h (rtol_p): Declare it. --- include/utils.h | 1 + src/utils.sc | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/include/utils.h b/include/utils.h index 03a8e2e..bc2952c 100644 --- a/include/utils.h +++ b/include/utils.h @@ -38,6 +38,7 @@ double gaussian_pdf (double x); double gaussian_cdf (double x); double rerror (double approx, double exact); +int rtol_p (double approx, double exact, double rtol); double bisection (gsl_function* f, double a, double b); double bisection_rlimit (gsl_function* f, double a, double b); diff --git a/src/utils.sc b/src/utils.sc index 20452b0..94b7dcd 100644 --- a/src/utils.sc +++ b/src/utils.sc @@ -89,6 +89,11 @@ the range [0,pi]." exact value EXACT." (return (fabs (- 1 (/ approx exact))))) +(define (rtol? approx exact rtol) (int double double double) + "Return 1 if the approximate value APPROX is within RTOL relative +tolerance of the exact value EXACT. Else, return 0." + (return (< (rerror approx exact) rtol))) + (sc-define-syntax (with-root-fsolver solver solver-type function a b body ...) (with-alloc solver gsl-root-fsolver* (gsl-root-fsolver-alloc solver-type) -- cgit v1.2.3