Skip to content

Commit ed3b89f

Browse files
committed
Fix inconsistencies and speed in C tests
* Delete unused macros * Delete mostly unused types * Replace format binary16 with E5M2 * Split overly large tests * Fix duplicate test names * Remove in-place tests that use same array as input
1 parent 9ae6e80 commit ed3b89f

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

test/cpfloat_test.ts

+26-22
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,15 @@ typedef union {
3535
#define CONST_PI 3.14159265358979323846
3636
#define CONST_SQRT2 1.41421356237309504880
3737

38-
#define MINFORMAT 0
39-
#define MAXFORMAT 2
4038
#define MINMODE -1
4139
#define MAXMODE 8
4240
#define NREPS 1000
4341

4442
/* Define default target formats. */
45-
// binary16, bfloat16, TensorFloat-32
46-
static size_t precision [] = {11, 8, 11};
47-
static size_t emax [] = {15, 127, 127};
48-
static size_t emin [] = {-14, -126, -126};
43+
// E5M2, bfloat16
44+
static size_t precision [] = {3, 8};
45+
static size_t emax [] = {15, 127};
46+
static size_t emin [] = {-14, -126};
4947
static size_t nformats = 2;
5048

5149
/* Structure for options and fixtures. */
@@ -324,7 +322,7 @@ void check_equality_double(double *x, double *y, size_t n) {
324322
for (size_t j = 0; j < n; j++) {
325323
if (!nan_safe_compare_double(x[j], y[j])) {
326324
printf("DOUBLE\n");
327-
printf("***\nj = %ld\nx = %23.15e [%" PRIu64 "]\ny = %23.15e [%" PRIu64 "]\n",
325+
printf("***\nj = %ld\nx = %23.15e [%" PRIu64 "]\ny = %23.15e [%" PRIu64 "]\n",
328326
j,
329327
x[j], *(uint64_t *)(x + j),
330328
y[j], *(uint64_t *)(y + j));
@@ -338,7 +336,7 @@ void check_equality_double_int(double *x, int *y, size_t n) {
338336
for (size_t j = 0; j < n; j++) {
339337
if (!nan_safe_compare_double(x[j], y[j])) {
340338
printf("DOUBLE\n");
341-
printf("***\nj = %ld\nx = %23.15e [%" PRIu64 "]\ny = %23.15e\n",
339+
printf("***\nj = %ld\nx = %23.15e [%" PRIu64 "]\ny = %23.15e\n",
342340
j, x[j], *(uint64_t *)(x + j), (double)y[j]);
343341
}
344342
ck_assert(nan_safe_compare_double(x[j], (double)y[j]));
@@ -916,15 +914,15 @@ for (size_t mode = 1; mode < 3; mode++) {
916914
double *zd = alloc_init_array_double(xd, n);
917915
double *yd = allocate_array_double(xd, n, mode);
918916
select_tests_det_double(yd, xd, zd, n, fpopts,
919-
MINMODE, MAXMODE, 0, 2, -1, -1);
917+
MINMODE, MAXMODE, 0, nformats - 1, -1, -1);
920918
free(zd);
921919
free_array_double(yd, mode);
922920

923921
float xf [] = {0, -0, inf_float(), -inf_float(), nan_float()};
924922
float *zf = alloc_init_array_float(xf, n);
925923
float *yf = allocate_array_float(xf, n, mode);
926924
select_tests_det_float(yf, xf, zf, n, fpopts,
927-
MINMODE, MAXMODE, 0, 2, -1, -1);
925+
MINMODE, MAXMODE, 0, nformats - 1, -1, -1);
928926
free(zf);
929927
free_array_float(yf, mode);
930928
}
@@ -2624,13 +2622,16 @@ free(onef);
26242622
free(exp);
26252623
free(lexp);
26262624

2627-
#test enumeration_floating_point_numbers
2628-
printf("4c. Next and previous floating-point number\n");
2625+
#test floating_point_enumeration_subnormal_numbers
2626+
printf("4c. Next and previous floating-point number: subnormal numbers\n");
2627+
fpopts->infinity = CPFLOAT_INF_USE;
26292628
fpopts->explim = CPFLOAT_EXPRANGE_TARG;
2629+
fpopts->saturation = CPFLOAT_SAT_NO;
26302630
fpopts->subnormal = CPFLOAT_SUBN_USE;
2631-
// Subnormals
2632-
for (size_t mode = 2; mode < 3; mode++) {
2631+
fpopts->round = CPFLOAT_RND_NE;
2632+
for (size_t mode = 3; mode < 3; mode++) {
26332633
for (size_t i = 0; i < nformats; i++) {
2634+
26342635
fpopts->precision = precision[i];
26352636
fpopts->emax = emax[i];
26362637
fpopts->emin = emin[i];
@@ -2653,8 +2654,10 @@ for (size_t mode = 2; mode < 3; mode++) {
26532654
copy_array_double(ad, refd, n);
26542655
cpf_nexttoward(xd, ad, infl, n-1, fpopts);
26552656
check_equality_double(xd, refd+1, n-1);
2657+
26562658
csign_intarray_double((uint64_t *)infd, n);
2657-
for (size_t j = 0; j < n; j++) infl[j] = -infl[j];
2659+
for (size_t j = 0; j < n; j++)
2660+
infl[j] = -infl[j];
26582661
copy_array_double(ad, refd, n);
26592662
cpf_nextafter(xd, ad+1, infd, n-1, fpopts);
26602663
check_equality_double(xd, refd, n-1);
@@ -2669,8 +2672,10 @@ for (size_t mode = 2; mode < 3; mode++) {
26692672
copy_array_double(ad, refd, n);
26702673
cpf_nexttoward(xd, ad+1, infl, n-1, fpopts);
26712674
check_equality_double(xd, refd, n-1);
2675+
26722676
csign_intarray_double((uint64_t *) infd, n);
2673-
for (size_t j = 0; j < n; j++) infl[j] = -infl[j];
2677+
for (size_t j = 0; j < n; j++)
2678+
infl[j] = -infl[j];
26742679
copy_array_double(ad, refd, n);
26752680
cpf_nextafter(xd, ad, infd, n-1, fpopts);
26762681
check_equality_double(xd, refd+1, n-1);
@@ -2729,8 +2734,9 @@ for (size_t mode = 2; mode < 3; mode++) {
27292734
}
27302735
}
27312736

2732-
// Normals
2733-
for (size_t mode = 2; mode < 3; mode++) {
2737+
#test floating_point_enumeration_normal_numbers
2738+
printf("4d. Next and previous floating-point number: normal numbers\n");
2739+
for (size_t mode = 3; mode < 3; mode++) {
27342740
for (size_t i = 0; i < nformats; i++) {
27352741
fpopts->precision = precision[i];
27362742
fpopts->emax = emax[i];
@@ -2839,12 +2845,10 @@ for (size_t mode = 2; mode < 3; mode++) {
28392845
}
28402846

28412847
#test integer_rounding
2842-
printf("4c. Integer rounding\n");
2843-
2848+
printf("4e. Integer rounding\n");
28442849
fpopts->emax = emax[1];
28452850
fpopts->emin = emin[1];
28462851
fpopts->precision = precision[1];
2847-
28482852
size_t n = 32;
28492853
double *xd = malloc(n * sizeof(*xd));
28502854
int *xi = malloc(n * sizeof(*xi));
@@ -3012,7 +3016,7 @@ check_equality_double_long_long(rd7, xll, n-3);
30123016

30133017

30143018
#test arithmetic_operations_large
3015-
printf("4d. Arithmetic operations on large arrays\n");
3019+
printf("4f. Arithmetic operations on large arrays\n");
30163020
size_t i = 0;
30173021
fpopts->precision = precision[i];
30183022
fpopts->emax = emax[i];

0 commit comments

Comments
 (0)