+2012-03-11 Bruno Haible <bruno@clisp.org>
+
+ exp2* tests: More tests.
+ * tests/test-exp2.h (test_function): Test all integral arguments that
+ don't need to overflow or denormalized numbers.
+ * tests/test-exp2.c (MAX_EXP, MIN_EXP): New macros.
+ * tests/test-exp2f.c (MAX_EXP, MIN_EXP): Likewise.
+ * tests/test-exp2l.c (MAX_EXP, MIN_EXP): Likewise.
+
2012-03-10 Bruno Haible <bruno@clisp.org>
log1pl-ieee: Work around test failure on AIX 7.1.
#define DOUBLE double
#define L_(literal) literal
#define MANT_DIG DBL_MANT_DIG
+#define MAX_EXP DBL_MAX_EXP
+#define MIN_EXP DBL_MIN_EXP
#define EXP2 exp2
#define RANDOM randomd
#include "test-exp2.h"
* (DOUBLE) (1U << ((MANT_DIG - 1 + 3) / 5))
* (DOUBLE) (1U << ((MANT_DIG - 1 + 4) / 5));
- /* Small integral arguments. */
+ /* Integral arguments. */
{
DOUBLE x = L_(0.0);
DOUBLE y = EXP2 (x);
ASSERT (y == L_(1.0));
}
- {
- DOUBLE x = L_(1.0);
- DOUBLE y = EXP2 (x);
- ASSERT (y == L_(2.0));
- }
- {
- DOUBLE x = L_(2.0);
- DOUBLE y = EXP2 (x);
- ASSERT (y == L_(4.0));
- }
/* <http://sourceware.org/bugzilla/show_bug.cgi?id=13824> */
-#if !(defined __linux__ && defined __sparc__)
+#if !(defined __linux__ && (defined __sparc__ || defined __powerpc__))
{
- DOUBLE x = L_(3.0);
- DOUBLE y = EXP2 (x);
- ASSERT (y == L_(8.0));
+ int e;
+ DOUBLE x;
+ DOUBLE y;
+ for (e = 0, x = L_(0.0), y = L_(1.0);
+ e <= MAX_EXP - 1;
+ e++, x = x + L_(1.0), y = y * L_(2.0))
+ {
+ /* Invariant: x = e, y = 2^e. */
+ DOUBLE z = EXP2 (x);
+ ASSERT (z == y);
+ }
}
{
- DOUBLE x = L_(4.0);
- DOUBLE y = EXP2 (x);
- ASSERT (y == L_(16.0));
+ int e;
+ DOUBLE x;
+ DOUBLE y;
+ for (e = 0, x = L_(0.0), y = L_(1.0);
+ e >= MIN_EXP - 1;
+ e--, x = x - L_(1.0), y = y * L_(0.5))
+ {
+ /* Invariant: x = e, y = 2^e. */
+ DOUBLE z = EXP2 (x);
+ ASSERT (z == y);
+ }
}
#endif
- {
- DOUBLE x = - L_(1.0);
- DOUBLE y = EXP2 (x);
- ASSERT (y == L_(0.5));
- }
- {
- DOUBLE x = - L_(2.0);
- DOUBLE y = EXP2 (x);
- ASSERT (y == L_(0.25));
- }
/* Randomized tests. */
{
#define DOUBLE float
#define L_(literal) literal##f
#define MANT_DIG FLT_MANT_DIG
+#define MAX_EXP FLT_MAX_EXP
+#define MIN_EXP FLT_MIN_EXP
#define EXP2 exp2f
#define RANDOM randomf
#include "test-exp2.h"
#define DOUBLE long double
#define L_(literal) literal##L
#define MANT_DIG LDBL_MANT_DIG
+#define MAX_EXP LDBL_MAX_EXP
+#define MIN_EXP LDBL_MIN_EXP
#define EXP2 exp2l
#define RANDOM randoml
#include "test-exp2.h"