summaryrefslogtreecommitdiff
path: root/src/regress/lib/libc/ieeefp/round/round.c
blob: b9fcd9771e88819a6cab42e2b947e041e29e25c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*	$NetBSD: round.c,v 1.1 1995/04/26 00:27:28 jtc Exp $	*/

/*
 * Written by J.T. Conklin, Apr 18, 1995
 * Public domain.
 */

#include <assert.h>
#include <stdlib.h>
#include <ieeefp.h>
#include <float.h>

int
main()
{
	/*
	 * This test would be better if it actually performed some
	 * calculations to verify the selected rounding mode.  But
	 * this is probably acceptable since the fp{get,set}round
	 * functions usually just get or set the processors fpu
	 * control word.
	 */

	assert(fpgetround() == FP_RN);
	assert(FLT_ROUNDS == 1);

	assert(fpsetround(FP_RP) == FP_RN);
	assert(fpgetround() == FP_RP);
	assert(FLT_ROUNDS == 2);

	assert(fpsetround(FP_RM) == FP_RP);
	assert(fpgetround() == FP_RM);
	assert(FLT_ROUNDS == 3);

	assert(fpsetround(FP_RZ) == FP_RM);
	assert(fpgetround() == FP_RZ);
	assert(FLT_ROUNDS == 0);

	assert(fpsetround(FP_RN) == FP_RZ);
	assert(fpgetround() == FP_RN);
	assert(FLT_ROUNDS == 1);

	exit(0);
}