Commit 9854e669 authored by Lev Walkin's avatar Lev Walkin

more debug and tolerance to a differnce in CANONICAL-XER precision

parent b5450704
...@@ -44,23 +44,42 @@ d2s(double d, int canonical) { ...@@ -44,23 +44,42 @@ d2s(double d, int canonical) {
* is as given in the (sample) and (canonical_sample) arguments. * is as given in the (sample) and (canonical_sample) arguments.
*/ */
static void static void
check_str_representation(double d, const char *sample, const char *canonical_sample, int lineno) { check_str_representation(double d, const char *sample,
const char *canonical_sample, int lineno) {
char *s0, *s1; char *s0, *s1;
s0 = d2s(d, 0); s0 = d2s(d, 0);
s1 = d2s(d, 1); s1 = d2s(d, 1);
if(sample) { if(sample) {
printf("%03d: Checking %g->[\"%s\"] against [\"%s\"]%s\n", printf("%03d: Checking %g->[\"%s\"] against [\"%s\"]%s\n", lineno, d,
lineno, d, s0, sample, s0, sample, canonical_sample ? " (canonical follows...)" : "");
canonical_sample ? " (canonical follows...)" : ""
);
assert(!strcmp(s0, sample)); assert(!strcmp(s0, sample));
} }
if(canonical_sample) { if(canonical_sample) {
printf("%03d: Checking %g->[\"%s\"] against [\"%s\"] (canonical)\n", if(*s1 == '<') {
printf(
"%03d: Checking %g->[\"%s\"] against [\"%s\"] "
"(canonical)\n",
lineno, d, s1, canonical_sample); lineno, d, s1, canonical_sample);
assert(!strcmp(s1, canonical_sample)); assert(!strcmp(s1, canonical_sample));
} else {
double reconstructed = strtod(s1, 0);
printf(
"%03d: Checking %g->[\"%s\"] against [\"%s\"]->%g "
"(canonical, 𝟄=%.17g %g)\n",
lineno, d, s1, canonical_sample, reconstructed,
fabs(reconstructed - d), 1e-52);
if(d != reconstructed) {
printf(
"WARNING: Difference in a small epsilon (given "
"%%.15g=%.15g, %%.17g=%.17g, %%.20g=%.20g, "
"reconstructed %%.15g=%.15g, %%.17g=%.17g, "
"%%.20g=%.20g)!\n",
d, d, d, reconstructed, reconstructed, reconstructed);
}
assert(fabs(d - reconstructed) < 1e-52);
}
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment