xref: /illumos-gate/usr/src/lib/libm/common/Q/ieee_funcl.c (revision 25c28e83beb90e7c80452a7c818c5e6f73a07dc8)
1 /*
2  * CDDL HEADER START
3  *
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.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
24  */
25 /*
26  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
27  * Use is subject to license terms.
28  */
29 
30 #if defined(ELFOBJ)
31 #pragma weak isinfl = __isinfl
32 #pragma weak isnormall = __isnormall
33 #pragma weak issubnormall = __issubnormall
34 #pragma weak iszerol = __iszerol
35 #pragma weak signbitl = __signbitl
36 #endif
37 
38 #include "libm.h"
39 
40 #if defined(__sparc)
41 int
42 isinfl(long double x) {
43 	int *px = (int *) &x;
44 	return ((px[0] & ~0x80000000) == 0x7fff0000 && px[1] == 0 &&
45 		px[2] == 0 && px[3] == 0);
46 }
47 
48 int
49 isnormall(long double x) {
50 	int *px = (int *) &x;
51 	return ((unsigned) ((px[0] & 0x7fff0000) - 0x10000) < 0x7ffe0000);
52 }
53 
54 int
55 issubnormall(long double x) {
56 	int *px = (int *) &x;
57 	px[0] &= ~0x80000000;
58 	return (px[0] < 0x00010000 && (px[0] | px[1] | px[2] | px[3]) != 0);
59 }
60 
61 int
62 iszerol(long double x) {
63 	int *px = (int *) &x;
64 	return (((px[0] & ~0x80000000) | px[1] | px[2] | px[3]) == 0);
65 }
66 
67 int
68 signbitl(long double x) {
69 	unsigned *px = (unsigned *) &x;
70 	return (px[0] >> 31);
71 }
72 #elif defined(__x86)
73 int
74 isinfl(long double x) {
75 	int *px = (int *) &x;
76 #if defined(HANDLE_UNSUPPORTED)
77 	return ((px[2] & 0x7fff) == 0x7fff &&
78 		((px[1] ^ 0x80000000) | px[0]) == 0);
79 #else
80 	return ((px[2] & 0x7fff) == 0x7fff &&
81 		((px[1] & ~0x80000000) | px[0]) == 0);
82 #endif
83 }
84 
85 int
86 isnormall(long double x) {
87 	int *px = (int *) &x;
88 #if defined(HANDLE_UNSUPPORTED)
89 	return ((unsigned) ((px[2] & 0x7fff) - 1) < 0x7ffe &&
90 		(px[1] & 0x80000000) != 0);
91 #else
92 	return ((unsigned) ((px[2] & 0x7fff) - 1) < 0x7ffe);
93 #endif
94 }
95 
96 int
97 issubnormall(long double x) {
98 	int *px = (int *) &x;
99 	return ((px[2] & 0x7fff) == 0 && (px[0] | px[1]) != 0);
100 }
101 
102 int
103 iszerol(long double x) {
104 	int *px = (int *) &x;
105 	return (((px[2] & 0x7fff) | px[0] | px[1]) == 0);
106 }
107 
108 int
109 signbitl(long double x) {
110 	unsigned *px = (unsigned *) &x;
111 	return ((px[2] >> 15) & 1);
112 }
113 #endif	/* defined(__sparc) || defined(__x86) */
114