From 0e121c064e051716bdfca892b210fa52c792ac29 Mon Sep 17 00:00:00 2001 From: Eric Kunze Date: Wed, 10 Apr 2024 15:26:55 -0700 Subject: Clarify error bound for non-normal values Signed-off-by: Eric Kunze Change-Id: I9678952cc78cdf90272ccd5179b6220c293d62f7 --- pseudocode/library/generic_helpers.tosac | 6 ++++++ pseudocode/library/numeric_accuracy_helpers.tosac | 14 ++++++++++++++ 2 files changed, 20 insertions(+) (limited to 'pseudocode') diff --git a/pseudocode/library/generic_helpers.tosac b/pseudocode/library/generic_helpers.tosac index 6dc2755..cffd55c 100644 --- a/pseudocode/library/generic_helpers.tosac +++ b/pseudocode/library/generic_helpers.tosac @@ -69,3 +69,9 @@ in_out_t maximum_u(); // return the minimum value when interpreting type in_out_t as an unsigned value as returned by the make_unsigned helper. in_out_t minimum_u(); + +// return true if the given value is a NaN. Only valid for floating-point types +bool is_a_NaN(fp64_t value); + +// return true if value is a normal fp64 value (Not zero, subnormal, infinite or NaN) +bool is_normal_fp64(fp64_t value); \ No newline at end of file diff --git a/pseudocode/library/numeric_accuracy_helpers.tosac b/pseudocode/library/numeric_accuracy_helpers.tosac index b89d898..dbff2dd 100644 --- a/pseudocode/library/numeric_accuracy_helpers.tosac +++ b/pseudocode/library/numeric_accuracy_helpers.tosac @@ -56,3 +56,17 @@ int normal_frac () { case fp8e5m2_t: return 2; } } + +double calcAbsErrorBound(double bound_magnitude, double bounds_value, + double lower_bound, double normal_divisor) { + double error_bound = 0.0; + // Avoid cases where we generate an error_bound of NaN by multiplying inf * 0 + if (is_finite(bounds_value) || abs(bound_magnitude) != 0.0) { + double value_bound = abs(bound_magnitude) * bounds_value; + if (lower_bound > 0) { + value_bound = max(lower_bound, value_bound); + } + error_bound = exp2(-normal_frac / normal_divisor) * value_bound; + } + return error_bound; +} \ No newline at end of file -- cgit v1.2.1