summaryrefslogtreecommitdiff
path: root/tests/test-float.c
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff.email>2024-10-20 15:21:43 +0200
committerJörg Frings-Fürst <debian@jff.email>2024-10-20 15:21:43 +0200
commit4682deeb62247d34de87f8e777f99e2d337fd377 (patch)
tree5bd5b5605b5f3a4b3c8ea7468c34c23094afdef4 /tests/test-float.c
parent00893e79fc62966067af1a106567db96bd170338 (diff)
New upstream version 1.3upstream/1.3upstream
Diffstat (limited to 'tests/test-float.c')
-rw-r--r--tests/test-float.c147
1 files changed, 138 insertions, 9 deletions
diff --git a/tests/test-float.c b/tests/test-float.c
index e9dc4609..7614e32e 100644
--- a/tests/test-float.c
+++ b/tests/test-float.c
@@ -20,8 +20,12 @@
#include <float.h>
-/* Check that FLT_RADIX is a constant expression. */
-int a[] = { FLT_RADIX };
+/* Check that some macros are constant expressions. */
+int a[] =
+ {
+ FLT_RADIX,
+ FLT_EVAL_METHOD /* added in ISO C 99 */
+ };
/* ----------------------- Check macros for 'float' ----------------------- */
@@ -29,9 +33,20 @@ int a[] = { FLT_RADIX };
int fb[] =
{
FLT_MANT_DIG, FLT_MIN_EXP, FLT_MAX_EXP,
- FLT_DIG, FLT_MIN_10_EXP, FLT_MAX_10_EXP
+ FLT_DIG, FLT_MIN_10_EXP, FLT_MAX_10_EXP,
+ FLT_HAS_SUBNORM, /* added in ISO C 11 */
+ FLT_DECIMAL_DIG, /* added in ISO C 11 */
+ FLT_IS_IEC_60559 /* added in ISO C 23 */
};
-float fc[] = { FLT_EPSILON, FLT_MIN, FLT_MAX };
+float fc[] =
+ {
+ FLT_EPSILON, FLT_MIN, FLT_MAX,
+ FLT_TRUE_MIN, /* added in ISO C 11 */
+ FLT_NORM_MAX /* added in ISO C 23 */
+ };
+#if 0 /* FLT_SNAN is not a constant expression on some platforms. */
+float fs = FLT_SNAN; /* added in ISO C 23 */
+#endif
/* ----------------------- Check macros for 'double' ----------------------- */
@@ -39,9 +54,20 @@ float fc[] = { FLT_EPSILON, FLT_MIN, FLT_MAX };
int db[] =
{
DBL_MANT_DIG, DBL_MIN_EXP, DBL_MAX_EXP,
- DBL_DIG, DBL_MIN_10_EXP, DBL_MAX_10_EXP
+ DBL_DIG, DBL_MIN_10_EXP, DBL_MAX_10_EXP,
+ DBL_HAS_SUBNORM, /* added in ISO C 11 */
+ DBL_DECIMAL_DIG, /* added in ISO C 11 */
+ DBL_IS_IEC_60559 /* added in ISO C 23 */
};
-double dc[] = { DBL_EPSILON, DBL_MIN, DBL_MAX };
+double dc[] =
+ {
+ DBL_EPSILON, DBL_MIN, DBL_MAX,
+ DBL_TRUE_MIN, /* added in ISO C 11 */
+ DBL_NORM_MAX /* added in ISO C 23 */
+ };
+#if 0 /* DBL_SNAN is not a constant expression on some platforms. */
+double ds = DBL_SNAN; /* added in ISO C 23 */
+#endif
/* -------------------- Check macros for 'long double' -------------------- */
@@ -49,17 +75,36 @@ double dc[] = { DBL_EPSILON, DBL_MIN, DBL_MAX };
int lb[] =
{
LDBL_MANT_DIG, LDBL_MIN_EXP, LDBL_MAX_EXP,
- LDBL_DIG, LDBL_MIN_10_EXP, LDBL_MAX_10_EXP
+ LDBL_DIG, LDBL_MIN_10_EXP, LDBL_MAX_10_EXP,
+ LDBL_HAS_SUBNORM, /* added in ISO C 11 */
+ LDBL_DECIMAL_DIG, /* added in ISO C 11 */
+ LDBL_IS_IEC_60559 /* added in ISO C 23 */
};
long double lc1 = LDBL_EPSILON;
long double lc2 = LDBL_MIN;
-#if 0 /* LDBL_MAX is not a constant expression on some platforms. */
+#if !GNULIB_defined_long_double_union
+/* LDBL_MAX is not a constant expression on some platforms. */
long double lc3 = LDBL_MAX;
#endif
+#if !GNULIB_defined_long_double_union
+/* LDBL_TRUE_MIN is not a constant expression on FreeBSD/i386. */
+long double lc4 = LDBL_TRUE_MIN; /* added in ISO C 11 */
+#endif
+#if !GNULIB_defined_long_double_union
+/* LDBL_MAX is not a constant expression on some platforms. */
+long double lc5 = LDBL_NORM_MAX; /* added in ISO C 23 */
+#endif
+#if 0
+/* LDBL_SNAN is not a constant expression on some platforms. */
+long double ls = LDBL_SNAN; /* added in ISO C 23 */
+#endif
/* ------------------------------------------------------------------------- */
#include "fpucw.h"
+#include "isnanf-nolibm.h"
+#include "isnand-nolibm.h"
+#include "isnanl-nolibm.h"
#include "macros.h"
#if FLT_RADIX == 2
@@ -220,6 +265,34 @@ test_float (void)
ASSERT (x <= 1.0f);
}
}
+
+ /* Check the value of FLT_HAS_SUBNORM. */
+ ASSERT (FLT_HAS_SUBNORM == 1);
+
+ /* Check the value of FLT_DECIMAL_DIG. */
+ ASSERT (FLT_DECIMAL_DIG == (int)(FLT_MANT_DIG * 0.3010299956639812 + 2));
+
+ /* Check the value of FLT_TRUE_MIN. */
+ ASSERT (FLT_TRUE_MIN > 0.0f);
+ {
+ volatile float x = FLT_TRUE_MIN * 0.5f;
+ ASSERT (x == 0.0f);
+ }
+
+ /* Check the value of FLT_IS_IEC_60559. */
+#if !defined __m68k__
+ ASSERT (FLT_IS_IEC_60559);
+#elif 0
+ /* It is not clear what this macro actually means. Cf.
+ <http://mailman.oakapple.net/pipermail/cfp-interest/2023-April/002760.html> */
+ ASSERT (!FLT_IS_IEC_60559);
+#endif
+
+ /* Check the value of FLT_NORM_MAX. */
+ ASSERT (FLT_NORM_MAX == FLT_MAX);
+
+ /* Check the value of FLT_SNAN. */
+ ASSERT (isnanf (FLT_SNAN));
}
/* ----------------------- Check macros for 'double' ----------------------- */
@@ -291,6 +364,34 @@ test_double (void)
ASSERT (x <= 1.0);
}
}
+
+ /* Check the value of DBL_HAS_SUBNORM. */
+ ASSERT (DBL_HAS_SUBNORM == 1);
+
+ /* Check the value of DBL_DECIMAL_DIG. */
+ ASSERT (DBL_DECIMAL_DIG == (int)(DBL_MANT_DIG * 0.3010299956639812 + 2));
+
+ /* Check the value of DBL_TRUE_MIN. */
+ ASSERT (DBL_TRUE_MIN > 0.0);
+ {
+ volatile double x = DBL_TRUE_MIN * 0.5;
+ ASSERT (x == 0.0);
+ }
+
+ /* Check the value of DBL_IS_IEC_60559. */
+#if !defined __m68k__
+ ASSERT (DBL_IS_IEC_60559);
+#elif 0
+ /* It is not clear what this macro actually means. Cf.
+ <http://mailman.oakapple.net/pipermail/cfp-interest/2023-April/002760.html> */
+ ASSERT (!DBL_IS_IEC_60559);
+#endif
+
+ /* Check the value of DBL_NORM_MAX. */
+ ASSERT (DBL_NORM_MAX == DBL_MAX);
+
+ /* Check the value of DBL_SNAN. */
+ ASSERT (isnand (DBL_SNAN));
}
/* -------------------- Check macros for 'long double' -------------------- */
@@ -359,6 +460,34 @@ test_long_double (void)
ASSERT (x <= 1.0L);
}
}
+
+ /* Check the value of LDBL_HAS_SUBNORM. */
+ ASSERT (LDBL_HAS_SUBNORM == 1);
+
+ /* Check the value of LDBL_DECIMAL_DIG. */
+ ASSERT (LDBL_DECIMAL_DIG == (int)(LDBL_MANT_DIG * 0.3010299956639812 + 2));
+
+ /* Check the value of LDBL_TRUE_MIN. */
+ ASSERT (LDBL_TRUE_MIN > 0.0L);
+ {
+ volatile long double x = LDBL_TRUE_MIN * 0.5L;
+ ASSERT (x == 0.0L);
+ }
+
+ /* Check the value of LDBL_IS_IEC_60559. */
+#if (LDBL_MANT_DIG == 53 || LDBL_MANT_DIG == 113) && !defined __m68k__
+ ASSERT (LDBL_IS_IEC_60559);
+#elif 0
+ /* It is not clear what this macro actually means. Cf.
+ <http://mailman.oakapple.net/pipermail/cfp-interest/2023-April/002760.html> */
+ ASSERT (!LDBL_IS_IEC_60559);
+#endif
+
+ /* Check the value of LDBL_NORM_MAX. */
+ ASSERT (LDBL_NORM_MAX == LDBL_MAX);
+
+ /* Check the value of LDBL_SNAN. */
+ ASSERT (isnanl (LDBL_SNAN));
}
int
@@ -377,7 +506,7 @@ main ()
END_LONG_DOUBLE_ROUNDING ();
}
- return 0;
+ return test_exit_status;
}
#else