xref: /openbsd/regress/lib/libc/ieeefp/round/round.c (revision 3cab2bb3)
1 /*	$OpenBSD: round.c,v 1.3 2003/07/31 21:48:03 deraadt Exp $	*/
2 /*	$NetBSD: round.c,v 1.1 1995/04/26 00:27:28 jtc Exp $	*/
3 
4 /*
5  * Written by J.T. Conklin, Apr 18, 1995
6  * Public domain.
7  */
8 
9 #include <assert.h>
10 #include <stdlib.h>
11 #include <ieeefp.h>
12 #include <float.h>
13 
14 int
15 main(int argc, char *argv[])
16 {
17 	/*
18 	 * This test would be better if it actually performed some
19 	 * calculations to verify the selected rounding mode.  But
20 	 * this is probably acceptable since the fp{get,set}round
21 	 * functions usually just get or set the processors fpu
22 	 * control word.
23 	 */
24 
25 	assert(fpgetround() == FP_RN);
26 	assert(FLT_ROUNDS == 1);
27 
28 	assert(fpsetround(FP_RP) == FP_RN);
29 	assert(fpgetround() == FP_RP);
30 	assert(FLT_ROUNDS == 2);
31 
32 	assert(fpsetround(FP_RM) == FP_RP);
33 	assert(fpgetround() == FP_RM);
34 	assert(FLT_ROUNDS == 3);
35 
36 	assert(fpsetround(FP_RZ) == FP_RM);
37 	assert(fpgetround() == FP_RZ);
38 	assert(FLT_ROUNDS == 0);
39 
40 	assert(fpsetround(FP_RN) == FP_RZ);
41 	assert(fpgetround() == FP_RN);
42 	assert(FLT_ROUNDS == 1);
43 
44 	exit(0);
45 }
46