4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 1988 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 /* IEEE function implementations. */
31 #include "base_conversion.h"
34 _class_single(single
*x
)
36 single_equivalence kluge
;
39 if (kluge
.f
.msw
.exponent
== 0) { /* 0 or sub */
40 if (kluge
.f
.msw
.significand
== 0)
44 } else if (kluge
.f
.msw
.exponent
== 0xff) { /* inf or nan */
45 if (kluge
.f
.msw
.significand
== 0)
47 else if (kluge
.f
.msw
.significand
>= 0x400000)
56 _class_extended(extended
*x
)
58 extended_equivalence kluge
;
63 if (kluge
.f
.msw
.exponent
== 0) { /* 0 or sub */
64 if ((kluge
.f
.significand
== 0) && (kluge
.f
.significand2
== 0))
68 } else if (kluge
.f
.msw
.exponent
== 0x7fff) { /* inf or nan */
69 if (((kluge
.f
.significand
& 0x7fffffff) == 0) && (kluge
.f
.significand2
== 0))
71 else if ((kluge
.f
.significand
& 0x7fffffff) >= 0x40000000)
80 _unpack_single(unpacked
*pu
, single
*px
)
86 (*pu
).sign
= x
.f
.msw
.sign
;
87 for (i
= 1; i
< UNPACKED_SIZE
; i
++)
88 pu
->significand
[i
] = 0;
89 if (x
.f
.msw
.exponent
== 0) { /* zero or sub */
90 if (x
.f
.msw
.significand
== 0) { /* zero */
91 pu
->fpclass
= fp_zero
;
93 } else { /* subnormal */
94 pu
->fpclass
= fp_normal
;
95 pu
->exponent
= -SINGLE_BIAS
;
96 pu
->significand
[0] = x
.f
.msw
.significand
<< 9;
100 } else if (x
.f
.msw
.exponent
== 0xff) { /* inf or nan */
101 if (x
.f
.msw
.significand
== 0) { /* inf */
102 pu
->fpclass
= fp_infinity
;
105 if ((x
.f
.msw
.significand
& 0x400000) != 0) { /* quiet */
106 pu
->fpclass
= fp_quiet
;
107 } else {/* signaling */
108 pu
->fpclass
= fp_quiet
;
109 _fp_set_exception(fp_invalid
);
111 pu
->significand
[0] = 0x40000000 | (x
.f
.msw
.significand
<< 8);
115 (*pu
).exponent
= x
.f
.msw
.exponent
- SINGLE_BIAS
;
116 (*pu
).fpclass
= fp_normal
;
117 (*pu
).significand
[0] = 0x80000000 | (x
.f
.msw
.significand
<< 8);
121 _unpack_extended(unpacked
*pu
, extended
*px
)
123 extended_equivalence x
;
129 pu
->sign
= x
.f
.msw
.sign
;
130 pu
->fpclass
= fp_normal
;
131 pu
->exponent
= x
.f
.msw
.exponent
- EXTENDED_BIAS
;
132 pu
->significand
[0] = x
.f
.significand
;
133 pu
->significand
[1] = x
.f
.significand2
;
134 for (i
= 2; i
< UNPACKED_SIZE
; i
++)
135 pu
->significand
[i
] = 0;
136 if (x
.f
.msw
.exponent
== 0x7fff) { /* inf or nan */
137 if (((x
.f
.significand
& 0x7fffffff) == 0) && (x
.f
.significand2
== 0)) { /* inf */
138 pu
->fpclass
= fp_infinity
;
141 if ((x
.f
.significand
& 0x40000000) != 0) { /* quiet */
142 pu
->fpclass
= fp_quiet
;
143 } else {/* signaling */
144 pu
->fpclass
= fp_quiet
;
145 _fp_set_exception(fp_invalid
);
150 if (x
.f
.significand
< 0x80000000) { /* zero or unnormal */
151 if ((x
.f
.significand
== 0) && (x
.f
.significand2
== 0)) { /* zero */
152 pu
->fpclass
= fp_zero
;
154 } else { /* unnormal */
155 pu
->fpclass
= fp_normal
;
163 _display_unpacked(unpacked
*pu
)
167 (void) printf(" unpacked ");
172 switch (pu
->fpclass
) {
177 (void) printf("Infinity");
180 (void) printf("NaN(quiet)");
183 (void) printf("NaN(signaling)");
187 e
= 1 + pu
->exponent
;
188 for (i
= 0; i
< UNPACKED_SIZE
; i
++) {
190 (void) printf(" %8X *2**%d + ", pu
->significand
[i
], e
);