8854 libm: variable set but not used
[unleashed.git] / usr / src / lib / libm / common / m9x / nexttowardl.c
blob9c30314b0fe99570a66a3a81b7cc656d5ca5482c
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
23 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
26 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
27 * Use is subject to license terms.
30 #pragma weak __nexttowardl = nexttowardl
32 #include "libm.h"
33 #include <float.h> /* LDBL_MAX, LDBL_MIN */
35 #if defined(__sparc)
36 #define n0 0
37 #define n1 1
38 #define n2 2
39 #define n3 3
40 #define X86PDNRM1(x)
41 #define INC(px) { \
42 if (++px[n3] == 0) \
43 if (++px[n2] == 0) \
44 if (++px[n1] == 0) \
45 ++px[n0]; \
47 #define DEC(px) { \
48 if (--px[n3] == 0xffffffff) \
49 if (--px[n2] == 0xffffffff) \
50 if (--px[n1] == 0xffffffff) \
51 --px[n0]; \
53 #elif defined(__x86)
54 #define n0 2
55 #define n1 1
56 #define n2 0
57 #define n3 0
59 * if pseudo-denormal, replace by the equivalent normal
61 #define X86PDNRM1(x) if (XBIASED_EXP(x) == 0 && (((int *) &x)[1] & \
62 0x80000000) != 0) \
63 ((int *) &x)[2] |= 1
64 #define INC(px) { \
65 if (++px[n2] == 0) \
66 if ((++px[n1] & ~0x80000000) == 0) \
67 px[n1] = 0x80000000, ++px[n0]; \
69 #define DEC(px) { \
70 if (--px[n2] == 0xffffffff) \
71 if (--px[n1] == 0x7fffffff) \
72 if ((--px[n0] & 0x7fff) != 0) \
73 px[n1] |= 0x80000000; \
75 #endif
77 long double
78 nexttowardl(long double x, long double y) {
79 int *px = (int *) &x;
80 int *py = (int *) &y;
82 if (x == y)
83 return (y); /* C99 requirement */
84 if (x != x || y != y)
85 return (x * y);
87 if (ISZEROL(x)) { /* x == 0.0 */
88 px[n0] = py[n0] & XSGNMSK;
89 px[n1] = px[n2] = 0;
90 px[n3] = 1;
91 } else {
92 X86PDNRM1(x);
93 if ((px[n0] & XSGNMSK) == 0) { /* x > 0.0 */
94 if (x > y) /* x > y */
95 DEC(px)
96 else
97 INC(px)
98 } else {
99 if (x < y) /* x < y */
100 DEC(px)
101 else
102 INC(px)
105 #ifndef lint
107 volatile long double dummy __unused;
108 int k = XBIASED_EXP(x);
110 if (k == 0)
111 dummy = LDBL_MIN * copysignl(LDBL_MIN, x);
112 else if (k == 0x7fff)
113 dummy = LDBL_MAX * copysignl(LDBL_MAX, x);
115 #endif
116 return (x);