commit 63b2eb872bc292e637a75e6919a2d8ab3024f295
parent ee5831cc6b1e53556cb2185446f53280c62b44c1
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Wed, 6 Mar 2024 16:05:35 +0100
Correction and adjustment of the swf_H3d_eval function
The sign was wrong in the terms of the series. The evaluated error is
also updated: there's no need to calculate the relative error, since the
target error is 0.
Diffstat:
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/swf.h b/src/swf.h
@@ -40,7 +40,7 @@ struct swf_H_tabulate_args {
double delta_x;
struct mem_allocator* allocator; /* NULL <=> use default allocator */
};
-#define SWF_H_TABULATE_ARGS_DEFAULT__ {1e-5, 3.88, 4e-5, NULL}
+#define SWF_H_TABULATE_ARGS_DEFAULT__ {0, 3.88, 1e-5, NULL}
static const struct swf_H_tabulate_args SWF_H_TABULATE_ARGS_DEFAULT =
SWF_H_TABULATE_ARGS_DEFAULT__;
diff --git a/src/swf_H.c b/src/swf_H.c
@@ -57,20 +57,20 @@ swf_H3d_eval(const double x)
{
double sign = -1; /* Sign of the term */
double sum = 0; /* Sum */
- double error = INF; /* Relative error */
+ double error = INF; /* Error */
unsigned k = 1; /* Index of the term */
- ASSERT(x < 0); /* Check pre-condition */
+ ASSERT(x >= 0); /* Check pre-condition */
if(x == 0) return 0;
do {
const double t = PI*(double)k;
- const double term = sign * exp(-t*t*x);
+ const double term = sign * exp(-(t*t)*x);
const double sum_next = sum + term;
- error = (sum_next - sum) / sum_next;
+ error = sum_next - sum;
sum = sum_next;
- sign *= sign;
+ sign *= -1;
} while(error != 0 && ++k < UINT_MAX);
return 1.0 + 2.0 * sum;