Print this page
5261 libm should stop using synonyms.h
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libm/common/m9x/nearbyint.c
+++ new/usr/src/lib/libm/common/m9x/nearbyint.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
24 24 */
25 25 /*
26 26 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
27 27 * Use is subject to license terms.
28 28 */
29 29
30 30 #pragma weak nearbyint = __nearbyint
31 31
↓ open down ↓ |
31 lines elided |
↑ open up ↑ |
32 32 /*
33 33 * nearbyint(x) returns the nearest fp integer to x in the direction
34 34 * corresponding to the current rounding direction without raising
35 35 * the inexact exception.
36 36 *
37 37 * nearbyint(x) is x unchanged if x is +/-0 or +/-inf. If x is NaN,
38 38 * nearbyint(x) is also NaN.
39 39 */
40 40
41 41 #include "libm.h"
42 -#include "fenv_synonyms.h"
43 42 #include <fenv.h>
44 43
45 44 double
46 45 __nearbyint(double x) {
47 46 union {
48 47 unsigned i[2];
49 48 double d;
50 49 } xx;
51 50 unsigned hx, sx, i, frac;
52 51 int rm, j;
53 52
54 53 xx.d = x;
55 54 sx = xx.i[HIWORD] & 0x80000000;
56 55 hx = xx.i[HIWORD] & ~0x80000000;
57 56
58 57 /* handle trivial cases */
59 58 if (hx >= 0x43300000) { /* x is nan, inf, or already integral */
60 59 if (hx >= 0x7ff00000) /* x is inf or nan */
61 60 #if defined(FPADD_TRAPS_INCOMPLETE_ON_NAN)
62 61 return (hx >= 0x7ff80000 ? x : x + x);
63 62 /* assumes sparc-like QNaN */
64 63 #else
65 64 return (x + x);
66 65 #endif
67 66 return (x);
68 67 } else if ((hx | xx.i[LOWORD]) == 0) /* x is zero */
69 68 return (x);
70 69
71 70 /* get the rounding mode */
72 71 rm = fegetround();
73 72
74 73 /* flip the sense of directed roundings if x is negative */
75 74 if (sx && (rm == FE_UPWARD || rm == FE_DOWNWARD))
76 75 rm = (FE_UPWARD + FE_DOWNWARD) - rm;
77 76
78 77 /* handle |x| < 1 */
79 78 if (hx < 0x3ff00000) {
80 79 if (rm == FE_UPWARD || (rm == FE_TONEAREST &&
81 80 (hx >= 0x3fe00000 && ((hx & 0xfffff) | xx.i[LOWORD]))))
82 81 xx.i[HIWORD] = sx | 0x3ff00000;
83 82 else
84 83 xx.i[HIWORD] = sx;
85 84 xx.i[LOWORD] = 0;
86 85 return (xx.d);
87 86 }
88 87
89 88 /* round x at the integer bit */
90 89 j = 0x433 - (hx >> 20);
91 90 if (j >= 32) {
92 91 i = 1 << (j - 32);
93 92 frac = ((xx.i[HIWORD] << 1) << (63 - j)) |
94 93 (xx.i[LOWORD] >> (j - 32));
95 94 if (xx.i[LOWORD] & (i - 1))
96 95 frac |= 1;
97 96 if (!frac)
98 97 return (x);
99 98 xx.i[LOWORD] = 0;
100 99 xx.i[HIWORD] &= ~(i - 1);
101 100 if ((rm == FE_UPWARD) || ((rm == FE_TONEAREST) &&
102 101 ((frac > 0x80000000u) || ((frac == 0x80000000) &&
103 102 (xx.i[HIWORD] & i)))))
104 103 xx.i[HIWORD] += i;
105 104 } else {
106 105 i = 1 << j;
107 106 frac = (xx.i[LOWORD] << 1) << (31 - j);
108 107 if (!frac)
109 108 return (x);
110 109 xx.i[LOWORD] &= ~(i - 1);
111 110 if ((rm == FE_UPWARD) || ((rm == FE_TONEAREST) &&
112 111 (frac > 0x80000000u || ((frac == 0x80000000) &&
113 112 (xx.i[LOWORD] & i))))) {
114 113 xx.i[LOWORD] += i;
115 114 if (xx.i[LOWORD] == 0)
116 115 xx.i[HIWORD]++;
117 116 }
118 117 }
119 118 return (xx.d);
120 119 }
↓ open down ↓ |
68 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX