#include "testconfig.h"
#define TEST_FUNC_FF_F __MATH_PRECNAME(drem)
#include "testdriver.h"


static test_ff_f_data const drem_data[] = {
	{ __LINE__, HEXCONSTE(1, 0x3fff, 0x80000000L, 0x00000000L), ZERO_P, QNAN_P, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION|ERRNO_EDOM },
	{ __LINE__, HEXCONSTE(1, 0x3fff, 0x80000000L, 0x00000000L), ZERO_M, QNAN_P, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION|ERRNO_EDOM },
	{ __LINE__, INF_P, ZERO_M, QNAN_P, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION|ERRNO_EDOM },
	{ __LINE__, INF_P, ZERO_P, QNAN_P, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION|ERRNO_EDOM },
	{ __LINE__, INF_P, HEXCONSTE(1, 0x3fff, 0x80000000L, 0x00000000L), QNAN_P, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION|ERRNO_EDOM },
	{ __LINE__, INF_P, HEXCONSTE(2, 0x4000, 0x80000000L, 0x00000000L), QNAN_P, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION|ERRNO_EDOM },
	{ __LINE__, INF_M, ZERO_M, QNAN_P, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION|ERRNO_EDOM },
	{ __LINE__, INF_M, ZERO_P, QNAN_P, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION|ERRNO_EDOM },
	{ __LINE__, INF_M, HEXCONSTE(1, 0x3fff, 0x80000000L, 0x00000000L), QNAN_P, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION|ERRNO_EDOM },
	{ __LINE__, INF_M, HEXCONSTE(2, 0x4000, 0x80000000L, 0x00000000L), QNAN_P, NO_INEXACT_EXCEPTION|INVALID_EXCEPTION|ERRNO_EDOM },
	{ __LINE__, QNAN_P, QNAN_P, QNAN_P, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED },
	{ __LINE__, ZERO_P, QNAN_P, QNAN_P, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED },
	{ __LINE__, QNAN_P, ZERO_P, QNAN_P, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED },

	{ __LINE__, HEXCONSTE(7.0, 0x4001, 0xe0000000L, 0x00000000L), INF_P, HEXCONSTE(7.0, 0x4001, 0xe0000000L, 0x00000000L), NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED|FLAG_FAIL_ARANYM }, /* returns NaN */
	{ __LINE__, HEXCONSTE(7.0, 0x4001, 0xe0000000L, 0x00000000L), INF_M, HEXCONSTE(7.0, 0x4001, 0xe0000000L, 0x00000000L), NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED|FLAG_FAIL_ARANYM }, /* returns NaN */

	{ __LINE__, HEXCONSTE(1.625, 0x3fff, 0xd0000000L, 0x00000000L), HEXCONSTE(1.0, 0x3fff, 0x80000000L, 0x00000000L), HEXCONSTE(-0.375, 0xbffd, 0xc0000000L, 0x00000000L), NO_INEXACT_EXCEPTION },
	{ __LINE__, HEXCONSTE(-1.625, 0xbfff, 0xd0000000L, 0x00000000L), HEXCONSTE(1.0, 0x3fff, 0x80000000L, 0x00000000L), HEXCONSTE(0.375, 0x3ffd, 0xc0000000L, 0x00000000L), NO_INEXACT_EXCEPTION },
	{ __LINE__, HEXCONSTE(1.625, 0x3fff, 0xd0000000L, 0x00000000L), HEXCONSTE(-1.0, 0xbfff, 0x80000000L, 0x00000000L), HEXCONSTE(-0.375, 0xbffd, 0xc0000000L, 0x00000000L), NO_INEXACT_EXCEPTION },
	{ __LINE__, HEXCONSTE(-1.625, 0xbfff, 0xd0000000L, 0x00000000L), HEXCONSTE(-1.0, 0xbfff, 0x80000000L, 0x00000000L), HEXCONSTE(0.375, 0x3ffd, 0xc0000000L, 0x00000000L), NO_INEXACT_EXCEPTION },
	{ __LINE__, HEXCONSTE(5.0, 0x4001, 0xa0000000L, 0x00000000L), HEXCONSTE(2.0, 0x4000, 0x80000000L, 0x00000000L), HEXCONSTE(1.0, 0x3fff, 0x80000000L, 0x00000000L), NO_INEXACT_EXCEPTION|FLAG_FAIL_ARANYM }, /* returns -1, which is OK */
	{ __LINE__, HEXCONSTE(3.0, 0x4000, 0xc0000000L, 0x00000000L), HEXCONSTE(2.0, 0x4000, 0x80000000L, 0x00000000L), HEXCONSTE(-1.0, 0xbfff, 0x80000000L, 0x00000000L), NO_INEXACT_EXCEPTION },
};


int main(int argc, char **argv)
{
	int status;
	
	status = 0;
	
	test_init(argc, argv);
	
	status |= test_table_ff_f(drem_data, ARRAY_SIZE(drem_data), __FILE__);
	
	return status ? EXIT_FAILURE : EXIT_SUCCESS;
}
