Home | History | Annotate | Line # | Download | only in libm
      1  1.21  riastrad /*	$NetBSD: t_fe_round.c,v 1.21 2025/04/17 13:45:22 riastradh Exp $	*/
      2  1.19  riastrad 
      3   1.1      maya /*
      4   1.1      maya  * Written by Maya Rashish <maya (at) NetBSD.org>
      5   1.1      maya  * Public domain.
      6   1.1      maya  *
      7   1.1      maya  * Testing IEEE-754 rounding modes (and lrint)
      8   1.1      maya  */
      9   1.1      maya 
     10  1.19  riastrad #include <sys/cdefs.h>
     11  1.21  riastrad __RCSID("$NetBSD: t_fe_round.c,v 1.21 2025/04/17 13:45:22 riastradh Exp $");
     12  1.19  riastrad 
     13   1.1      maya #include <atf-c.h>
     14   1.1      maya #include <fenv.h>
     15   1.1      maya #include <math.h>
     16  1.12       kre #include <stdint.h>
     17   1.1      maya #include <stdio.h>
     18   1.1      maya #include <stdlib.h>
     19   1.1      maya 
     20  1.19  riastrad #ifdef __HAVE_FENV
     21  1.19  riastrad 
     22   1.1      maya /*#pragma STDC FENV_ACCESS ON gcc?? */
     23   1.1      maya 
     24   1.1      maya #define INT 9223L
     25   1.1      maya 
     26  1.10  riastrad static const char *
     27  1.10  riastrad rmname(int rm)
     28  1.10  riastrad {
     29  1.10  riastrad 	switch (rm) {
     30  1.10  riastrad 	case FE_TOWARDZERO:
     31  1.10  riastrad 		return "FE_TOWARDZERO";
     32  1.10  riastrad 	case FE_DOWNWARD:
     33  1.10  riastrad 		return "FE_DOWNWARD";
     34  1.10  riastrad 	case FE_UPWARD:
     35  1.10  riastrad 		return "FE_UPWARD";
     36  1.10  riastrad 	case FE_TONEAREST:
     37  1.10  riastrad 		return "FE_TONEAREST";
     38  1.10  riastrad 	default:
     39  1.10  riastrad 		return "unknown";
     40  1.10  riastrad 	}
     41  1.10  riastrad }
     42  1.10  riastrad 
     43  1.19  riastrad /*
     44  1.19  riastrad  * Examples are chosen to fit within the smallest single-precision
     45  1.19  riastrad  * format any NetBSD port uses, so that we can write the examples once
     46  1.19  riastrad  * in type double, and convert to single without raising inexact-result
     47  1.19  riastrad  * exceptions when we're trying to test whether the integer-rounding
     48  1.19  riastrad  * functions raise them.
     49  1.19  riastrad  */
     50   1.1      maya static const struct {
     51   1.1      maya 	int round_mode;
     52   1.1      maya 	double input;
     53   1.1      maya 	long int expected;
     54   1.1      maya } values[] = {
     55  1.16  riastrad 	{ FE_DOWNWARD,		3.75,		3},
     56  1.16  riastrad 	{ FE_DOWNWARD,		-3.75,		-4},
     57  1.16  riastrad 	{ FE_DOWNWARD,		+0.,		0},
     58  1.19  riastrad 	{ FE_DOWNWARD,		-0.,		0},
     59  1.16  riastrad 	{ FE_DOWNWARD,		-INT-0.0625,	-INT-1},
     60  1.16  riastrad 	{ FE_DOWNWARD,		+INT-0.0625,	INT-1},
     61  1.16  riastrad 	{ FE_DOWNWARD,		-INT+0.0625,	-INT},
     62  1.16  riastrad 	{ FE_DOWNWARD,		+INT+0.0625,	INT},
     63   1.1      maya 
     64  1.19  riastrad 	{ FE_UPWARD,		+0.,		0},
     65  1.16  riastrad 	{ FE_UPWARD,		-0.,		0},
     66  1.16  riastrad 	{ FE_UPWARD,		-123.75,	-123},
     67  1.16  riastrad 	{ FE_UPWARD,		123.75,		124},
     68  1.16  riastrad 	{ FE_UPWARD,		-INT-0.0625,	-INT},
     69  1.16  riastrad 	{ FE_UPWARD,		+INT-0.0625,	INT},
     70  1.16  riastrad 	{ FE_UPWARD,		-INT+0.0625,	-INT+1},
     71  1.16  riastrad 	{ FE_UPWARD,		+INT+0.0625,	INT+1},
     72  1.16  riastrad 
     73  1.16  riastrad 	{ FE_TOWARDZERO,	1.9375,		1},
     74  1.16  riastrad 	{ FE_TOWARDZERO,	-1.9375,	-1},
     75  1.16  riastrad 	{ FE_TOWARDZERO,	0.25,		0},
     76  1.16  riastrad 	{ FE_TOWARDZERO,	INT+0.0625,	INT},
     77  1.16  riastrad 	{ FE_TOWARDZERO,	INT-0.0625,	INT - 1},
     78  1.16  riastrad 	{ FE_TOWARDZERO,	-INT+0.0625,	-INT + 1},
     79  1.16  riastrad 	{ FE_TOWARDZERO,	+0.,		0},
     80  1.16  riastrad 	{ FE_TOWARDZERO,	-0.,		0},
     81  1.16  riastrad 
     82  1.16  riastrad 	{ FE_TONEAREST,		-INT-0.0625,	-INT},
     83  1.16  riastrad 	{ FE_TONEAREST,		+INT-0.0625,	INT},
     84  1.16  riastrad 	{ FE_TONEAREST,		-INT+0.0625,	-INT},
     85  1.16  riastrad 	{ FE_TONEAREST,		+INT+0.0625,	INT},
     86  1.16  riastrad 	{ FE_TONEAREST,		-INT-0.53125,	-INT-1},
     87  1.16  riastrad 	{ FE_TONEAREST,		+INT-0.53125,	INT-1},
     88  1.16  riastrad 	{ FE_TONEAREST,		-INT+0.53125,	-INT+1},
     89  1.16  riastrad 	{ FE_TONEAREST,		+INT+0.53125,	INT+1},
     90  1.16  riastrad 	{ FE_TONEAREST,		+0.,		0},
     91  1.16  riastrad 	{ FE_TONEAREST,		-0.,		0},
     92   1.1      maya };
     93   1.1      maya 
     94  1.16  riastrad ATF_TC(fe_lrint);
     95  1.16  riastrad ATF_TC_HEAD(fe_lrint, tc)
     96   1.1      maya {
     97  1.16  riastrad 	atf_tc_set_md_var(tc, "descr",
     98  1.16  riastrad 	    "Checking IEEE 754 rounding modes using lrint(3)");
     99   1.1      maya }
    100   1.1      maya 
    101  1.16  riastrad ATF_TC_BODY(fe_lrint, tc)
    102   1.1      maya {
    103  1.16  riastrad 	enum {
    104  1.16  riastrad 		LLRINT,
    105  1.16  riastrad 		LLRINTF,
    106  1.16  riastrad 		LRINT,
    107  1.16  riastrad 		LRINTF,
    108  1.16  riastrad 		N_FN,
    109  1.16  riastrad 	} fn;
    110  1.16  riastrad 	static const char *const fnname[] = {
    111  1.16  riastrad 		[LLRINT] = "llrint",
    112  1.16  riastrad 		[LLRINTF] = "llrintf",
    113  1.16  riastrad 		[LRINT] = "lrint",
    114  1.16  riastrad 		[LRINTF] = "lrintf",
    115  1.16  riastrad 	};
    116   1.1      maya 	long int received;
    117  1.16  riastrad 	unsigned i;
    118   1.1      maya 
    119  1.16  riastrad 	for (i = 0; i < __arraycount(values); i++) {
    120  1.16  riastrad 		for (fn = 0; fn < N_FN; fn++) {
    121  1.16  riastrad 			/*
    122  1.16  riastrad 			 * Set the requested rounding mode.
    123  1.16  riastrad 			 */
    124  1.16  riastrad 			fesetround(values[i].round_mode);
    125  1.16  riastrad 
    126  1.16  riastrad 			/*
    127  1.16  riastrad 			 * Call the lrint(3)-family function.
    128  1.16  riastrad 			 */
    129  1.16  riastrad 			switch (fn) {
    130  1.16  riastrad 			case LLRINT:
    131  1.16  riastrad 				received = llrint(values[i].input);
    132  1.16  riastrad 				break;
    133  1.16  riastrad 			case LLRINTF:
    134  1.16  riastrad 				received = llrintf(values[i].input);
    135  1.16  riastrad 				break;
    136  1.16  riastrad 			case LRINT:
    137  1.16  riastrad 				received = lrint(values[i].input);
    138  1.16  riastrad 				break;
    139  1.16  riastrad 			case LRINTF:
    140  1.16  riastrad 				received = lrintf(values[i].input);
    141  1.16  riastrad 				break;
    142  1.16  riastrad 			default:
    143  1.16  riastrad 				atf_tc_fail("impossible");
    144  1.16  riastrad 			}
    145  1.16  riastrad 
    146  1.16  riastrad 			/*
    147  1.16  riastrad 			 * Assuming the result we got has zero
    148  1.16  riastrad 			 * fractional part, casting to long int should
    149  1.16  riastrad 			 * have no rounding.  Verify it matches the
    150  1.16  riastrad 			 * integer we expect.
    151  1.16  riastrad 			 */
    152  1.16  riastrad 			ATF_CHECK_MSG((long int)received == values[i].expected,
    153  1.16  riastrad 			    "[%u] %s %s(%f): got %ld, expected %ld",
    154  1.16  riastrad 			    i, rmname(values[i].round_mode), fnname[fn],
    155  1.16  riastrad 			    values[i].input,
    156  1.16  riastrad 			    (long int)received, values[i].expected);
    157  1.16  riastrad 
    158  1.16  riastrad 			/* Do we get the same rounding mode out? */
    159  1.16  riastrad 			ATF_CHECK_MSG(fegetround() == values[i].round_mode,
    160  1.16  riastrad 			    "[%u] %s: set %d (%s), got %d (%s)",
    161  1.16  riastrad 			    i, fnname[fn],
    162  1.16  riastrad 			    values[i].round_mode, rmname(values[i].round_mode),
    163  1.16  riastrad 			    fegetround(), rmname(fegetround()));
    164  1.16  riastrad 		}
    165   1.1      maya 	}
    166   1.1      maya }
    167   1.1      maya 
    168  1.16  riastrad ATF_TC(fe_nearbyint_rint);
    169  1.16  riastrad ATF_TC_HEAD(fe_nearbyint_rint, tc)
    170   1.6        he {
    171  1.10  riastrad 	atf_tc_set_md_var(tc, "descr",
    172  1.16  riastrad 	    "Checking IEEE 754 rounding modes using nearbyint/rint");
    173   1.6        he }
    174   1.6        he 
    175  1.16  riastrad ATF_TC_BODY(fe_nearbyint_rint, tc)
    176   1.6        he {
    177  1.16  riastrad 	enum {
    178  1.16  riastrad 		NEARBYINT,
    179  1.16  riastrad 		NEARBYINTF,
    180  1.16  riastrad 		NEARBYINTL,
    181  1.16  riastrad 		RINT,
    182  1.16  riastrad 		RINTF,
    183  1.16  riastrad 		RINTL,
    184  1.16  riastrad 		N_FN,
    185  1.16  riastrad 	} fn;
    186  1.16  riastrad 	static const char *const fnname[] = {
    187  1.16  riastrad 		[NEARBYINT] = "nearbyint",
    188  1.16  riastrad 		[NEARBYINTF] = "nearbyintf",
    189  1.16  riastrad 		[NEARBYINTL] = "nearbyintl",
    190  1.16  riastrad 		[RINT] = "rint",
    191  1.16  riastrad 		[RINTF] = "rintf",
    192  1.16  riastrad 		[RINTL] = "rintl",
    193  1.16  riastrad 	};
    194  1.10  riastrad 	double received, ipart, fpart;
    195  1.16  riastrad 	unsigned i;
    196   1.6        he 
    197  1.21  riastrad #ifdef __sparc64__
    198  1.21  riastrad 	atf_tc_expect_fail("PR port-sparc64/59310:"
    199  1.21  riastrad 	    " t_fe_round:fe_nearbyint_rint tests are failing");
    200  1.21  riastrad #endif
    201  1.21  riastrad 
    202  1.16  riastrad 	for (i = 0; i < __arraycount(values); i++) {
    203  1.16  riastrad 		for (fn = 0; fn < N_FN; fn++) {
    204  1.16  riastrad 			bool expect_except =
    205  1.16  riastrad 			    values[i].input != (double)values[i].expected;
    206  1.16  riastrad 
    207  1.16  riastrad 			/*
    208  1.16  riastrad 			 * Set the requested rounding mode.
    209  1.16  riastrad 			 */
    210  1.16  riastrad 			fesetround(values[i].round_mode);
    211  1.16  riastrad 
    212  1.17  riastrad #ifdef __ia64__
    213  1.17  riastrad /*
    214  1.17  riastrad  * Without this barrier, we get:
    215  1.17  riastrad  *
    216  1.17  riastrad  * /tmp//ccJayu9g.s:2793: Warning: Use of 'mov.m' violates RAW dependency 'AR[FPSR].sf0.flags' (impliedf)
    217  1.17  riastrad  * /tmp//ccJayu9g.s:2793: Warning: Only the first path encountering the conflict is reported
    218  1.17  riastrad  * /tmp//ccJayu9g.s:2757: Warning: This is the location of the conflicting usage
    219  1.17  riastrad  *
    220  1.17  riastrad  * (If you fix this, remove the entry from doc/HACKS.)
    221  1.17  riastrad  */
    222  1.17  riastrad 			__insn_barrier();
    223  1.17  riastrad #endif
    224  1.17  riastrad 
    225  1.16  riastrad 			/*
    226  1.16  riastrad 			 * Clear sticky floating-point exception bits
    227  1.16  riastrad 			 * so we can verify whether the FE_INEXACT
    228  1.16  riastrad 			 * exception is raised.
    229  1.16  riastrad 			 */
    230  1.16  riastrad 			feclearexcept(FE_ALL_EXCEPT);
    231  1.16  riastrad 
    232  1.16  riastrad 			/*
    233  1.16  riastrad 			 * Call the rint(3)-family function.
    234  1.16  riastrad 			 */
    235  1.16  riastrad 			switch (fn) {
    236  1.16  riastrad 			case NEARBYINT:
    237  1.16  riastrad 				received = nearbyint(values[i].input);
    238  1.16  riastrad 				expect_except = false;
    239  1.16  riastrad 				break;
    240  1.16  riastrad 			case NEARBYINTF:
    241  1.16  riastrad 				received = nearbyintf(values[i].input);
    242  1.16  riastrad 				expect_except = false;
    243  1.16  riastrad 				break;
    244  1.16  riastrad 			case NEARBYINTL:
    245  1.16  riastrad 				received = nearbyintl(values[i].input);
    246  1.16  riastrad 				expect_except = false;
    247  1.16  riastrad 				break;
    248  1.16  riastrad 			case RINT:
    249  1.16  riastrad 				received = rint(values[i].input);
    250  1.16  riastrad 				break;
    251  1.16  riastrad 			case RINTF:
    252  1.16  riastrad 				received = rintf(values[i].input);
    253  1.16  riastrad 				break;
    254  1.16  riastrad 			case RINTL:
    255  1.16  riastrad 				received = rintl(values[i].input);
    256  1.16  riastrad 				break;
    257  1.16  riastrad 			default:
    258  1.16  riastrad 				atf_tc_fail("impossible");
    259  1.16  riastrad 			}
    260  1.16  riastrad 
    261  1.16  riastrad 			/*
    262  1.16  riastrad 			 * Verify FE_INEXACT was raised or not,
    263  1.16  riastrad 			 * depending on whether there was rounding and
    264  1.16  riastrad 			 * whether the function is supposed to raise
    265  1.16  riastrad 			 * exceptions.
    266  1.16  riastrad 			 */
    267  1.16  riastrad 			if (expect_except) {
    268  1.16  riastrad 				ATF_CHECK_MSG(fetestexcept(FE_INEXACT) != 0,
    269  1.16  riastrad 				    "[%u] %s %s(%f)"
    270  1.16  riastrad 				    " failed to raise FE_INEXACT",
    271  1.16  riastrad 				    i, rmname(values[i].round_mode),
    272  1.16  riastrad 				    fnname[fn], values[i].input);
    273  1.16  riastrad 			} else {
    274  1.16  riastrad 				ATF_CHECK_MSG(fetestexcept(FE_INEXACT) == 0,
    275  1.16  riastrad 				    "[%u] %s %s(%f)"
    276  1.16  riastrad 				    " spuriously raised FE_INEXACT",
    277  1.16  riastrad 				    i, rmname(values[i].round_mode),
    278  1.16  riastrad 				    fnname[fn], values[i].input);
    279  1.16  riastrad 			}
    280  1.16  riastrad 
    281  1.16  riastrad 			/*
    282  1.16  riastrad 			 * Verify the fractional part of the result is
    283  1.16  riastrad 			 * zero -- the result of rounding to an integer
    284  1.16  riastrad 			 * is supposed to be an integer.
    285  1.16  riastrad 			 */
    286  1.16  riastrad 			fpart = modf(received, &ipart);
    287  1.16  riastrad 			ATF_CHECK_MSG(fpart == 0,
    288  1.16  riastrad 			    "[%u] %s %s(%f)=%f has fractional part %f"
    289  1.16  riastrad 			    " (integer part %f)",
    290  1.16  riastrad 			    i, rmname(values[i].round_mode), fnname[fn],
    291  1.16  riastrad 			    values[i].input, received, fpart, ipart);
    292  1.16  riastrad 
    293  1.16  riastrad 			/*
    294  1.16  riastrad 			 * Assuming the result we got has zero
    295  1.16  riastrad 			 * fractional part, casting to long int should
    296  1.16  riastrad 			 * have no rounding.  Verify it matches the
    297  1.16  riastrad 			 * integer we expect.
    298  1.16  riastrad 			 */
    299  1.16  riastrad 			ATF_CHECK_MSG((long int)received == values[i].expected,
    300  1.16  riastrad 			    "[%u] %s %s(%f): got %f, expected %ld",
    301  1.16  riastrad 			    i, rmname(values[i].round_mode), fnname[fn],
    302  1.16  riastrad 			    values[i].input, received, values[i].expected);
    303  1.16  riastrad 
    304  1.16  riastrad 			/* Do we get the same rounding mode out? */
    305  1.16  riastrad 			ATF_CHECK_MSG(fegetround() == values[i].round_mode,
    306  1.16  riastrad 			    "[%u] %s: set %d (%s), got %d (%s)",
    307  1.16  riastrad 			    i, fnname[fn],
    308  1.16  riastrad 			    values[i].round_mode, rmname(values[i].round_mode),
    309  1.16  riastrad 			    fegetround(), rmname(fegetround()));
    310  1.16  riastrad 		}
    311   1.6        he 	}
    312   1.6        he }
    313   1.6        he 
    314  1.11  riastrad #ifdef __HAVE_LONG_DOUBLE
    315  1.11  riastrad 
    316  1.11  riastrad /*
    317  1.11  riastrad  * Use one bit more than fits in IEEE 754 binary64.
    318  1.11  riastrad  */
    319  1.11  riastrad static const struct {
    320  1.11  riastrad 	int round_mode;
    321  1.11  riastrad 	long double input;
    322  1.16  riastrad 	int64_t expected;
    323  1.11  riastrad } valuesl[] = {
    324  1.13  riastrad 	{ FE_TOWARDZERO,	0x2.00000000000008p+52L, 0x20000000000000 },
    325  1.13  riastrad 	{ FE_DOWNWARD,		0x2.00000000000008p+52L, 0x20000000000000 },
    326  1.13  riastrad 	{ FE_UPWARD,		0x2.00000000000008p+52L, 0x20000000000001 },
    327  1.13  riastrad 	{ FE_TONEAREST,		0x2.00000000000008p+52L, 0x20000000000000 },
    328  1.13  riastrad 	{ FE_TOWARDZERO,	0x2.00000000000018p+52L, 0x20000000000001 },
    329  1.13  riastrad 	{ FE_DOWNWARD,		0x2.00000000000018p+52L, 0x20000000000001 },
    330  1.13  riastrad 	{ FE_UPWARD,		0x2.00000000000018p+52L, 0x20000000000002 },
    331  1.13  riastrad 	{ FE_TONEAREST,		0x2.00000000000018p+52L, 0x20000000000002 },
    332  1.11  riastrad };
    333  1.11  riastrad 
    334  1.16  riastrad ATF_TC(fe_nearbyintl_rintl);
    335  1.16  riastrad ATF_TC_HEAD(fe_nearbyintl_rintl, tc)
    336  1.11  riastrad {
    337  1.11  riastrad 	atf_tc_set_md_var(tc, "descr",
    338  1.16  riastrad 	    "Checking IEEE 754 rounding modes using nearbyintl/rintl");
    339  1.11  riastrad }
    340  1.11  riastrad 
    341  1.16  riastrad ATF_TC_BODY(fe_nearbyintl_rintl, tc)
    342  1.11  riastrad {
    343  1.16  riastrad 	enum {
    344  1.16  riastrad 		RINTL,
    345  1.16  riastrad 		NEARBYINTL,
    346  1.16  riastrad 		N_FN,
    347  1.16  riastrad 	} fn;
    348  1.16  riastrad 	static const char *const fnname[] = {
    349  1.16  riastrad 		[RINTL] = "rintl",
    350  1.16  riastrad 		[NEARBYINTL] = "nearbyintl",
    351  1.16  riastrad 	};
    352  1.11  riastrad 	long double received, ipart, fpart;
    353  1.16  riastrad 	unsigned i;
    354  1.11  riastrad 
    355  1.21  riastrad #ifdef __sparc64__
    356  1.21  riastrad 	atf_tc_expect_fail("PR port-sparc64/59310:"
    357  1.21  riastrad 	    " t_fe_round:fe_nearbyint_rint tests are failing");
    358  1.21  riastrad #endif
    359  1.21  riastrad 
    360  1.16  riastrad 	for (i = 0; i < __arraycount(valuesl); i++) {
    361  1.16  riastrad 		for (fn = 0; fn < N_FN; fn++) {
    362  1.16  riastrad 			bool expect_except =
    363  1.16  riastrad 			    (valuesl[i].input !=
    364  1.16  riastrad 				(long double)valuesl[i].expected);
    365  1.16  riastrad 
    366  1.16  riastrad 			/*
    367  1.16  riastrad 			 * Set the requested rounding mode.
    368  1.16  riastrad 			 */
    369  1.16  riastrad 			fesetround(valuesl[i].round_mode);
    370  1.16  riastrad 
    371  1.16  riastrad 			/*
    372  1.16  riastrad 			 * Clear sticky floating-point exception bits
    373  1.16  riastrad 			 * so we can verify whether the FE_INEXACT
    374  1.16  riastrad 			 * exception is raised.
    375  1.16  riastrad 			 */
    376  1.16  riastrad 			feclearexcept(FE_ALL_EXCEPT);
    377  1.16  riastrad 
    378  1.16  riastrad 			/*
    379  1.16  riastrad 			 * Call the rint(3)-family function.
    380  1.16  riastrad 			 */
    381  1.16  riastrad 			switch (fn) {
    382  1.16  riastrad 			case NEARBYINTL:
    383  1.16  riastrad 				received = nearbyintl(valuesl[i].input);
    384  1.16  riastrad 				expect_except = false;
    385  1.16  riastrad 				break;
    386  1.16  riastrad 			case RINTL:
    387  1.16  riastrad 				received = rintl(valuesl[i].input);
    388  1.16  riastrad 				break;
    389  1.16  riastrad 			default:
    390  1.16  riastrad 				atf_tc_fail("impossible");
    391  1.16  riastrad 			}
    392  1.16  riastrad 
    393  1.16  riastrad 			/*
    394  1.16  riastrad 			 * Verify FE_INEXACT was raised or not,
    395  1.16  riastrad 			 * depending on whether there was rounding and
    396  1.16  riastrad 			 * whether the function is supposed to raise
    397  1.16  riastrad 			 * exceptions.
    398  1.16  riastrad 			 */
    399  1.16  riastrad 			if (expect_except) {
    400  1.16  riastrad 				ATF_CHECK_MSG(fetestexcept(FE_INEXACT) != 0,
    401  1.16  riastrad 				    "[%u] %s %s(%Lf)"
    402  1.16  riastrad 				    " failed to raise FE_INEXACT",
    403  1.16  riastrad 				    i, rmname(valuesl[i].round_mode),
    404  1.16  riastrad 				    fnname[fn], valuesl[i].input);
    405  1.16  riastrad 			} else {
    406  1.16  riastrad 				ATF_CHECK_MSG(fetestexcept(FE_INEXACT) == 0,
    407  1.16  riastrad 				    "[%u] %s %s(%Lf)"
    408  1.16  riastrad 				    " spuriously raised FE_INEXACT",
    409  1.16  riastrad 				    i, rmname(valuesl[i].round_mode),
    410  1.16  riastrad 				    fnname[fn], valuesl[i].input);
    411  1.16  riastrad 			}
    412  1.16  riastrad 
    413  1.16  riastrad 			/*
    414  1.16  riastrad 			 * Verify the fractional part of the result is
    415  1.16  riastrad 			 * zero -- the result of rounding to an integer
    416  1.16  riastrad 			 * is supposed to be an integer.
    417  1.16  riastrad 			 */
    418  1.16  riastrad 			fpart = modfl(received, &ipart);
    419  1.16  riastrad 			ATF_CHECK_MSG(fpart == 0,
    420  1.16  riastrad 			    "[%u] %s %s(%Lf)=%Lf has fractional part %Lf"
    421  1.16  riastrad 			    " (integer part %Lf)",
    422  1.16  riastrad 			    i, rmname(valuesl[i].round_mode), fnname[fn],
    423  1.16  riastrad 			    valuesl[i].input, received, fpart, ipart);
    424  1.16  riastrad 
    425  1.16  riastrad 			/*
    426  1.16  riastrad 			 * Assuming the result we got has zero
    427  1.16  riastrad 			 * fractional part, casting to int64_t should
    428  1.16  riastrad 			 * have no rounding.  Verify it matches the
    429  1.16  riastrad 			 * integer we expect.
    430  1.16  riastrad 			 */
    431  1.16  riastrad 			ATF_CHECK_MSG(((int64_t)received ==
    432  1.16  riastrad 				valuesl[i].expected),
    433  1.16  riastrad 			    "[%u] %s %s(%Lf): got %Lf, expected %jd",
    434  1.16  riastrad 			    i, rmname(valuesl[i].round_mode), fnname[fn],
    435  1.16  riastrad 			    valuesl[i].input, received, valuesl[i].expected);
    436  1.16  riastrad 
    437  1.16  riastrad 			/* Do we get the same rounding mode out? */
    438  1.16  riastrad 			ATF_CHECK_MSG(fegetround() == valuesl[i].round_mode,
    439  1.16  riastrad 			    "[%u] %s: set %d (%s), got %d (%s)",
    440  1.16  riastrad 			    i, fnname[fn],
    441  1.16  riastrad 			    valuesl[i].round_mode,
    442  1.16  riastrad 			    rmname(valuesl[i].round_mode),
    443  1.16  riastrad 			    fegetround(), rmname(fegetround()));
    444  1.16  riastrad 		}
    445  1.11  riastrad 	}
    446  1.11  riastrad }
    447  1.11  riastrad 
    448  1.19  riastrad #endif	/* __HAVE_LONG_DOUBLE */
    449   1.7        he 
    450   1.1      maya ATF_TP_ADD_TCS(tp)
    451   1.1      maya {
    452   1.1      maya 
    453  1.16  riastrad 	ATF_TP_ADD_TC(tp, fe_lrint);
    454  1.16  riastrad 	ATF_TP_ADD_TC(tp, fe_nearbyint_rint);
    455  1.11  riastrad #ifdef __HAVE_LONG_DOUBLE
    456  1.16  riastrad 	ATF_TP_ADD_TC(tp, fe_nearbyintl_rintl);
    457  1.11  riastrad #endif
    458   1.1      maya 
    459   1.1      maya 	return atf_no_error();
    460   1.1      maya }
    461   1.1      maya 
    462  1.19  riastrad #else  /* !__HAVE_FENV */
    463   1.1      maya 
    464  1.19  riastrad ATF_TP_ADD_TCS(tp)
    465   1.7        he {
    466   1.6        he 
    467  1.19  riastrad 	/*
    468  1.19  riastrad 	 * No fenv, no fesetround to test.
    469  1.19  riastrad 	 */
    470   1.1      maya 	return atf_no_error();
    471   1.1      maya }
    472   1.1      maya 
    473  1.19  riastrad #endif	/* __HAVE_FENV */
    474