kernel: remove unused utsname_set_machine()
[unleashed.git] / usr / src / lib / libc / sparcv9 / fp / _Qp_qtox.c
blobc9caaf09ab7594348c26841e5d2acbb9f5fc890d
1 /*
2 * CDDL HEADER START
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
7 * with the License.
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]
20 * CDDL HEADER END
23 * Copyright (c) 1994-1997, by Sun Microsystems, Inc.
24 * All rights reserved.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include "quad.h"
32 * _Qp_qtox(x) returns (long)*x.
34 long
35 _Qp_qtox(const union longdouble *x)
37 long i, round;
38 unsigned int xm, fsr;
40 xm = x->l.msw & 0x7fffffff;
42 __quad_getfsrp(&fsr);
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) {
51 /* signal inexact */
52 if (fsr & FSR_NXM) {
53 __quad_fqtox(x, &i);
54 } else {
55 fsr = (fsr & ~FSR_CEXC) | FSR_NXA |
56 FSR_NXC;
57 __quad_setfsrp(&fsr);
60 return (i);
62 i = ((x->l.msw & 0x80000000)? 0x8000000000000000ul :
63 0x7fffffffffffffffl);
64 if (fsr & FSR_NVM) {
65 __quad_fqtox(x, &i);
66 } else {
67 fsr = (fsr & ~FSR_CEXC) | FSR_NVA | FSR_NVC;
68 __quad_setfsrp(&fsr);
70 return (i);
72 if (xm < 0x3fff0000) {
73 i = 0l;
74 if (xm | x->l.frac2 | x->l.frac3 | x->l.frac4) {
75 /* signal inexact */
76 if (fsr & FSR_NXM) {
77 __quad_fqtox(x, &i);
78 } else {
79 fsr = (fsr & ~FSR_CEXC) | FSR_NXA | FSR_NXC;
80 __quad_setfsrp(&fsr);
83 return (i);
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)
92 i = -i;
93 if (round | (x->l.frac3 & 0x3ffff) | x->l.frac4) {
94 /* signal inexact */
95 if (fsr & FSR_NXM) {
96 __quad_fqtox(x, &i);
97 } else {
98 fsr = (fsr & ~FSR_CEXC) | FSR_NXA | FSR_NXC;
99 __quad_setfsrp(&fsr);
102 return (i);