Print this page
5261 libm should stop using synonyms.h
5298 fabs is 0-sized, confuses dis(1) and others
Reviewed by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
Approved by: Gordon Ross <gwr@nexenta.com>
5262 libm needs to be carefully unifdef'd
5268 libm doesn't need to hide symbols which are already local
Reviewed by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
Reviewed by: Igor Kozhukhov <ikozhukhov@gmail.com>
Reviewed by: Gordon Ross <gwr@nexenta.com>
Approved by: Gordon Ross <gwr@nexenta.com>
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 -#include "fenv_synonyms.h"
45 42 #include <fenv.h>
46 43
47 44 double
48 45 __nearbyint(double x) {
49 46 union {
50 47 unsigned i[2];
51 48 double d;
52 49 } xx;
53 50 unsigned hx, sx, i, frac;
54 51 int rm, j;
55 52
56 53 xx.d = x;
57 54 sx = xx.i[HIWORD] & 0x80000000;
58 55 hx = xx.i[HIWORD] & ~0x80000000;
59 56
60 57 /* handle trivial cases */
61 58 if (hx >= 0x43300000) { /* x is nan, inf, or already integral */
62 59 if (hx >= 0x7ff00000) /* x is inf or nan */
63 60 #if defined(FPADD_TRAPS_INCOMPLETE_ON_NAN)
64 61 return (hx >= 0x7ff80000 ? x : x + x);
65 62 /* assumes sparc-like QNaN */
66 63 #else
67 64 return (x + x);
68 65 #endif
69 66 return (x);
70 67 } else if ((hx | xx.i[LOWORD]) == 0) /* x is zero */
71 68 return (x);
72 69
73 70 /* get the rounding mode */
74 71 rm = fegetround();
75 72
76 73 /* flip the sense of directed roundings if x is negative */
77 74 if (sx && (rm == FE_UPWARD || rm == FE_DOWNWARD))
78 75 rm = (FE_UPWARD + FE_DOWNWARD) - rm;
79 76
80 77 /* handle |x| < 1 */
81 78 if (hx < 0x3ff00000) {
82 79 if (rm == FE_UPWARD || (rm == FE_TONEAREST &&
83 80 (hx >= 0x3fe00000 && ((hx & 0xfffff) | xx.i[LOWORD]))))
84 81 xx.i[HIWORD] = sx | 0x3ff00000;
85 82 else
86 83 xx.i[HIWORD] = sx;
87 84 xx.i[LOWORD] = 0;
88 85 return (xx.d);
89 86 }
90 87
91 88 /* round x at the integer bit */
92 89 j = 0x433 - (hx >> 20);
93 90 if (j >= 32) {
94 91 i = 1 << (j - 32);
95 92 frac = ((xx.i[HIWORD] << 1) << (63 - j)) |
96 93 (xx.i[LOWORD] >> (j - 32));
97 94 if (xx.i[LOWORD] & (i - 1))
98 95 frac |= 1;
99 96 if (!frac)
100 97 return (x);
101 98 xx.i[LOWORD] = 0;
102 99 xx.i[HIWORD] &= ~(i - 1);
103 100 if ((rm == FE_UPWARD) || ((rm == FE_TONEAREST) &&
104 101 ((frac > 0x80000000u) || ((frac == 0x80000000) &&
105 102 (xx.i[HIWORD] & i)))))
106 103 xx.i[HIWORD] += i;
107 104 } else {
108 105 i = 1 << j;
109 106 frac = (xx.i[LOWORD] << 1) << (31 - j);
110 107 if (!frac)
111 108 return (x);
112 109 xx.i[LOWORD] &= ~(i - 1);
113 110 if ((rm == FE_UPWARD) || ((rm == FE_TONEAREST) &&
114 111 (frac > 0x80000000u || ((frac == 0x80000000) &&
115 112 (xx.i[LOWORD] & i))))) {
116 113 xx.i[LOWORD] += i;
117 114 if (xx.i[LOWORD] == 0)
118 115 xx.i[HIWORD]++;
119 116 }
120 117 }
121 118 return (xx.d);
122 119 }
↓ open down ↓ |
68 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX