turns printfs back on
[freebsd-src/fkvm-freebsd.git] / tools / regression / lib / msun / test-lrint.c
blob1693a34ae5b811386e152bc88f8165770bcf320a
1 /*-
2 * Copyright (c) 2005-2008 David Schultz <das@FreeBSD.org>
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
28 * Test for lrint(), lrintf(), llrint(), and llrintf().
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
34 #include <assert.h>
35 #include <fenv.h>
36 #include <limits.h>
37 #include <math.h>
38 #include <stdio.h>
40 #ifdef __i386__
41 #include <ieeefp.h>
42 #endif
44 #define test(func, x, result, excepts) do { \
45 assert(feclearexcept(FE_ALL_EXCEPT) == 0); \
46 assert((func)(x) == (result) || fetestexcept(FE_INVALID)); \
47 assert(fetestexcept(FE_ALL_EXCEPT) == (excepts)); \
48 } while (0)
50 #define testall(x, result, excepts) do { \
51 test(lrint, x, result, excepts); \
52 test(lrintf, x, result, excepts); \
53 test(lrintl, x, result, excepts); \
54 test(llrint, x, result, excepts); \
55 test(llrintf, x, result, excepts); \
56 test(llrintl, x, result, excepts); \
57 } while (0)
59 #define IGNORE 0
61 #pragma STDC FENV_ACCESS ON
63 void
64 run_tests(void)
67 assert(fesetround(FE_DOWNWARD) == 0);
68 testall(0.75, 0, FE_INEXACT);
69 testall(-0.5, -1, FE_INEXACT);
71 assert(fesetround(FE_TONEAREST) == 0);
72 testall(0.0, 0, 0);
73 testall(0.25, 0, FE_INEXACT);
74 testall(0.5, 0, FE_INEXACT);
75 testall(-2.5, -2, FE_INEXACT);
76 testall(1.0, 1, 0);
77 testall(0x12345000p0, 0x12345000, 0);
78 testall(0x1234.fp0, 0x1235, FE_INEXACT);
79 testall(INFINITY, IGNORE, FE_INVALID);
80 testall(NAN, IGNORE, FE_INVALID);
82 #if (LONG_MAX == 0x7fffffffl)
83 assert(fesetround(FE_UPWARD) == 0);
84 test(lrint, 0x7fffffff.8p0, IGNORE, FE_INVALID);
85 test(lrint, -0x80000000.4p0, -0x80000000l, FE_INEXACT);
87 assert(fesetround(FE_DOWNWARD) == 0);
88 test(lrint, -0x80000000.8p0, IGNORE, FE_INVALID);
89 test(lrint, 0x80000000.0p0, IGNORE, FE_INVALID);
90 test(lrint, 0x7fffffff.4p0, 0x7fffffffl, FE_INEXACT);
91 test(lrintf, 0x80000000.0p0f, IGNORE, FE_INVALID);
92 test(lrintf, 0x7fffff80.0p0f, 0x7fffff80l, 0);
94 assert(fesetround(FE_TOWARDZERO) == 0);
95 test(lrint, 0x7fffffff.8p0, 0x7fffffffl, FE_INEXACT);
96 test(lrint, -0x80000000.8p0, -0x80000000l, FE_INEXACT);
97 test(lrint, 0x80000000.0p0, IGNORE, FE_INVALID);
98 test(lrintf, 0x80000000.0p0f, IGNORE, FE_INVALID);
99 test(lrintf, 0x7fffff80.0p0f, 0x7fffff80l, 0);
100 #elif (LONG_MAX == 0x7fffffffffffffffll)
101 assert(fesetround(FE_TONEAREST) == 0);
102 test(lrint, 0x8000000000000000.0p0, IGNORE, FE_INVALID);
103 test(lrintf, 0x8000000000000000.0p0f, IGNORE, FE_INVALID);
104 test(lrint, 0x7ffffffffffffc00.0p0, 0x7ffffffffffffc00l, 0);
105 test(lrintf, 0x7fffff8000000000.0p0f, 0x7fffff8000000000l, 0);
106 test(lrint, -0x8000000000000800.0p0, IGNORE, FE_INVALID);
107 test(lrintf, -0x8000010000000000.0p0f, IGNORE, FE_INVALID);
108 test(lrint, -0x8000000000000000.0p0, -0x8000000000000000l, 0);
109 test(lrintf, -0x8000000000000000.0p0f, -0x8000000000000000l, 0);
110 #else
111 #error "Unsupported long size"
112 #endif
114 #if (LLONG_MAX == 0x7fffffffffffffffLL)
115 assert(fesetround(FE_TONEAREST) == 0);
116 test(llrint, 0x8000000000000000.0p0, IGNORE, FE_INVALID);
117 test(llrintf, 0x8000000000000000.0p0f, IGNORE, FE_INVALID);
118 test(llrint, 0x7ffffffffffffc00.0p0, 0x7ffffffffffffc00ll, 0);
119 test(llrintf, 0x7fffff8000000000.0p0f, 0x7fffff8000000000ll, 0);
120 test(llrint, -0x8000000000000800.0p0, IGNORE, FE_INVALID);
121 test(llrintf, -0x8000010000000000.0p0f, IGNORE, FE_INVALID);
122 test(llrint, -0x8000000000000000.0p0, -0x8000000000000000ll, 0);
123 test(llrintf, -0x8000000000000000.0p0f, -0x8000000000000000ll, 0);
124 #else
125 #error "Unsupported long long size"
126 #endif
130 main(int argc, char *argv[])
133 printf("1..1\n");
135 run_tests();
136 #ifdef __i386__
137 fpsetprec(FP_PE);
138 run_tests();
139 #endif
141 printf("ok 1 - lrint\n");
143 return (0);