Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/lib/libc/locale When comparing doubles (any floating p...



details:   https://anonhg.NetBSD.org/src/rev/e485b5e9ff34
branches:  trunk
changeset: 828041:e485b5e9ff34
user:      kre <kre%NetBSD.org@localhost>
date:      Fri Nov 24 21:30:43 2017 +0000

description:
When comparing doubles (any floating point values) which have been
computed using different methods, don't expect to achieve identical
results (here, one constant is perhaps converted to binary from a string by
a cross compiler, the other is converted at run time).   Allow them to
have a small difference (for now, small is < 1e-7 - the constant is ~ 1e5,
so this is 12 orders of magnitude less) before failing (and include the
actual difference in the error message if it does fail.)

diffstat:

 tests/lib/libc/locale/t_sprintf.c |  15 +++++++++------
 1 files changed, 9 insertions(+), 6 deletions(-)

diffs (45 lines):

diff -r 069e9be5ac54 -r e485b5e9ff34 tests/lib/libc/locale/t_sprintf.c
--- a/tests/lib/libc/locale/t_sprintf.c Fri Nov 24 18:45:59 2017 +0000
+++ b/tests/lib/libc/locale/t_sprintf.c Fri Nov 24 21:30:43 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: t_sprintf.c,v 1.4 2017/11/23 23:47:09 kre Exp $ */
+/* $NetBSD: t_sprintf.c,v 1.5 2017/11/24 21:30:43 kre Exp $ */
 
 /*-
  * Copyright (c) 2017 The NetBSD Foundation, Inc.
@@ -32,9 +32,10 @@
 #include <sys/cdefs.h>
 __COPYRIGHT("@(#) Copyright (c) 2017\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_sprintf.c,v 1.4 2017/11/23 23:47:09 kre Exp $");
+__RCSID("$NetBSD: t_sprintf.c,v 1.5 2017/11/24 21:30:43 kre Exp $");
 
 #include <locale.h>
+#include <math.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -125,7 +126,7 @@
 static void
 h_strto(const struct test *t)
 {
-       double d;
+       double d, diff;
 
        ATF_REQUIRE_STREQ(setlocale(LC_ALL, "C"), "C");
        printf("Trying locale %s...\n", t->locale);
@@ -133,9 +134,11 @@
 
        ATF_REQUIRE_EQ((int)strtol(t->int_input, NULL, 10), t->int_value);
        d = strtod(t->double_input, NULL);
-       ATF_REQUIRE_EQ_MSG(d, t->double_value, "In %s: "
-           "strtod(t->double_input[%s], NULL)[%g] != t->double_value[%g]",
-           t->locale, t->double_input, d, t->double_value);
+       if ((diff = fabs(d - t->double_value)) > 1e-7)
+               ATF_REQUIRE_EQ_MSG(d, t->double_value, "In %s: d=strtod("
+                   "t->double_input[%s], NULL)[%.9g] != t->double_value[%.9g]"
+                   ": diff=%g", t->locale, t->double_input, d,
+                   t->double_value, diff);
 }
 
 static void



Home | Main Index | Thread Index | Old Index