Print this page
5262 libm needs to be carefully unifdef'd
5268 libm doesn't need to hide symbols which are already local
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
↓ open down ↓ |
19 lines elided |
↑ open up ↑ |
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 -#if defined(ELFOBJ)
31 30 #pragma weak nearbyint = __nearbyint
32 -#endif
33 31
34 32 /*
35 33 * nearbyint(x) returns the nearest fp integer to x in the direction
36 34 * corresponding to the current rounding direction without raising
37 35 * the inexact exception.
38 36 *
39 37 * nearbyint(x) is x unchanged if x is +/-0 or +/-inf. If x is NaN,
40 38 * nearbyint(x) is also NaN.
41 39 */
42 40
43 41 #include "libm.h"
44 42 #include "fenv_synonyms.h"
45 43 #include <fenv.h>
46 44
47 45 double
48 46 __nearbyint(double x) {
49 47 union {
50 48 unsigned i[2];
51 49 double d;
52 50 } xx;
53 51 unsigned hx, sx, i, frac;
54 52 int rm, j;
55 53
56 54 xx.d = x;
57 55 sx = xx.i[HIWORD] & 0x80000000;
58 56 hx = xx.i[HIWORD] & ~0x80000000;
59 57
60 58 /* handle trivial cases */
61 59 if (hx >= 0x43300000) { /* x is nan, inf, or already integral */
62 60 if (hx >= 0x7ff00000) /* x is inf or nan */
63 61 #if defined(FPADD_TRAPS_INCOMPLETE_ON_NAN)
64 62 return (hx >= 0x7ff80000 ? x : x + x);
65 63 /* assumes sparc-like QNaN */
66 64 #else
67 65 return (x + x);
68 66 #endif
69 67 return (x);
70 68 } else if ((hx | xx.i[LOWORD]) == 0) /* x is zero */
71 69 return (x);
72 70
73 71 /* get the rounding mode */
74 72 rm = fegetround();
75 73
76 74 /* flip the sense of directed roundings if x is negative */
77 75 if (sx && (rm == FE_UPWARD || rm == FE_DOWNWARD))
78 76 rm = (FE_UPWARD + FE_DOWNWARD) - rm;
79 77
80 78 /* handle |x| < 1 */
81 79 if (hx < 0x3ff00000) {
82 80 if (rm == FE_UPWARD || (rm == FE_TONEAREST &&
83 81 (hx >= 0x3fe00000 && ((hx & 0xfffff) | xx.i[LOWORD]))))
84 82 xx.i[HIWORD] = sx | 0x3ff00000;
85 83 else
86 84 xx.i[HIWORD] = sx;
87 85 xx.i[LOWORD] = 0;
88 86 return (xx.d);
89 87 }
90 88
91 89 /* round x at the integer bit */
92 90 j = 0x433 - (hx >> 20);
93 91 if (j >= 32) {
94 92 i = 1 << (j - 32);
95 93 frac = ((xx.i[HIWORD] << 1) << (63 - j)) |
96 94 (xx.i[LOWORD] >> (j - 32));
97 95 if (xx.i[LOWORD] & (i - 1))
98 96 frac |= 1;
99 97 if (!frac)
100 98 return (x);
101 99 xx.i[LOWORD] = 0;
102 100 xx.i[HIWORD] &= ~(i - 1);
103 101 if ((rm == FE_UPWARD) || ((rm == FE_TONEAREST) &&
104 102 ((frac > 0x80000000u) || ((frac == 0x80000000) &&
105 103 (xx.i[HIWORD] & i)))))
106 104 xx.i[HIWORD] += i;
107 105 } else {
108 106 i = 1 << j;
109 107 frac = (xx.i[LOWORD] << 1) << (31 - j);
110 108 if (!frac)
111 109 return (x);
112 110 xx.i[LOWORD] &= ~(i - 1);
113 111 if ((rm == FE_UPWARD) || ((rm == FE_TONEAREST) &&
114 112 (frac > 0x80000000u || ((frac == 0x80000000) &&
115 113 (xx.i[LOWORD] & i))))) {
116 114 xx.i[LOWORD] += i;
117 115 if (xx.i[LOWORD] == 0)
118 116 xx.i[HIWORD]++;
119 117 }
120 118 }
121 119 return (xx.d);
122 120 }
↓ open down ↓ |
80 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX