xref: /illumos-gate/usr/src/lib/libm/common/Q/ieee_funcl.c (revision 1ec68d33)
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 #pragma weak isinfl = __isinfl
31 #pragma weak isnormall = __isnormall
32 #pragma weak issubnormall = __issubnormall
33 #pragma weak iszerol = __iszerol
34 #pragma weak signbitl = __signbitl
35 
36 #include "libm.h"
37 
38 #if defined(__sparc)
39 int
40 isinfl(long double x) {
41 	int *px = (int *) &x;
42 	return ((px[0] & ~0x80000000) == 0x7fff0000 && px[1] == 0 &&
43 		px[2] == 0 && px[3] == 0);
44 }
45 
46 int
47 isnormall(long double x) {
48 	int *px = (int *) &x;
49 	return ((unsigned) ((px[0] & 0x7fff0000) - 0x10000) < 0x7ffe0000);
50 }
51 
52 int
53 issubnormall(long double x) {
54 	int *px = (int *) &x;
55 	px[0] &= ~0x80000000;
56 	return (px[0] < 0x00010000 && (px[0] | px[1] | px[2] | px[3]) != 0);
57 }
58 
59 int
60 iszerol(long double x) {
61 	int *px = (int *) &x;
62 	return (((px[0] & ~0x80000000) | px[1] | px[2] | px[3]) == 0);
63 }
64 
65 int
66 signbitl(long double x) {
67 	unsigned *px = (unsigned *) &x;
68 	return (px[0] >> 31);
69 }
70 #elif defined(__x86)
71 int
72 isinfl(long double x) {
73 	int *px = (int *) &x;
74 #if defined(HANDLE_UNSUPPORTED)
75 	return ((px[2] & 0x7fff) == 0x7fff &&
76 		((px[1] ^ 0x80000000) | px[0]) == 0);
77 #else
78 	return ((px[2] & 0x7fff) == 0x7fff &&
79 		((px[1] & ~0x80000000) | px[0]) == 0);
80 #endif
81 }
82 
83 int
84 isnormall(long double x) {
85 	int *px = (int *) &x;
86 #if defined(HANDLE_UNSUPPORTED)
87 	return ((unsigned) ((px[2] & 0x7fff) - 1) < 0x7ffe &&
88 		(px[1] & 0x80000000) != 0);
89 #else
90 	return ((unsigned) ((px[2] & 0x7fff) - 1) < 0x7ffe);
91 #endif
92 }
93 
94 int
95 issubnormall(long double x) {
96 	int *px = (int *) &x;
97 	return ((px[2] & 0x7fff) == 0 && (px[0] | px[1]) != 0);
98 }
99 
100 int
101 iszerol(long double x) {
102 	int *px = (int *) &x;
103 	return (((px[2] & 0x7fff) | px[0] | px[1]) == 0);
104 }
105 
106 int
107 signbitl(long double x) {
108 	unsigned *px = (unsigned *) &x;
109 	return ((px[2] >> 15) & 1);
110 }
111 #endif	/* defined(__sparc) || defined(__x86) */
112