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 (c) 1994-1997, by Sun Microsystems, Inc.
24 * All rights reserved.
27 #pragma ident "%Z%%M% %I% %E% SMI"
32 * _Qp_qtox(x) returns (long)*x.
35 _Qp_qtox(const union longdouble
*x
)
40 xm
= x
->l
.msw
& 0x7fffffff;
44 /* handle nan, inf, and out-of-range cases */
45 if (xm
>= 0x403e0000) {
46 if (x
->l
.msw
== 0xc03e0000 && x
->l
.frac2
== 0 &&
47 (x
->l
.frac3
& 0xfffe0000) == 0) {
48 /* return largest negative 64 bit int */
49 i
= 0x8000000000000000ul
;
50 if ((x
->l
.frac3
& 0x1ffff) | x
->l
.frac4
) {
55 fsr
= (fsr
& ~FSR_CEXC
) | FSR_NXA
|
62 i
= ((x
->l
.msw
& 0x80000000)? 0x8000000000000000ul
:
67 fsr
= (fsr
& ~FSR_CEXC
) | FSR_NVA
| FSR_NVC
;
72 if (xm
< 0x3fff0000) {
74 if (xm
| x
->l
.frac2
| x
->l
.frac3
| x
->l
.frac4
) {
79 fsr
= (fsr
& ~FSR_CEXC
) | FSR_NXA
| FSR_NXC
;
86 /* now x is in the range of 64 bit int */
87 i
= 0x4000000000000000l
| ((long) (xm
& 0xffff) << 46) |
88 ((long) x
->l
.frac2
<< 14) | (x
->l
.frac3
>> 18);
89 round
= i
& ((1l << (0x403d - (xm
>> 16))) - 1);
90 i
>>= (0x403d - (xm
>> 16));
91 if (x
->l
.msw
& 0x80000000)
93 if (round
| (x
->l
.frac3
& 0x3ffff) | x
->l
.frac4
) {
98 fsr
= (fsr
& ~FSR_CEXC
) | FSR_NXA
| FSR_NXC
;