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, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
8 *
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.
13 *
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]
19 *
20 * CDDL HEADER END
21 */
22 #pragma ident "%Z%%M% %I% %E% SMI"
23
24 /*
25 * Copyright (c) 1987 by Sun Microsystems, Inc.
26 */
27
28 unsigned
_dtou(d)29 _dtou(d)
30 double d;
31 {
32 /* Convert double to unsigned. */
33
34 int id;
35
36 /*
37 * id = d is correct if 0 <= d < 2**31, and good enough if d is NaN
38 * or d < 0 or d >= 2**32. Otherwise, since the result (int) d of
39 * converting 2**31 <= d < 2**32 is unknown, adjust d before the
40 * conversion.
41 */
42
43 if (d >= 2147483648.0)
44 id = 0x80000000 | (int) (d - 2147483648.0);
45 else
46 id = (int) d;
47 return (unsigned) id;
48 }
49
50 unsigned
_ftou(dd)51 _ftou(dd)
52 int dd; /* really float */
53 {
54 /* Convert float to unsigned. */
55
56 int id;
57 double d = (double) *((float *)(&dd));
58 /*
59 * id = d is correct if 0 <= d < 2**31, and good enough if d is NaN
60 * or d < 0 or d >= 2**32. Otherwise, since the result (int) d of
61 * converting 2**31 <= d < 2**32 is unknown, adjust d before the
62 * conversion.
63 */
64
65 if (d >= 2147483648.0)
66 id = 0x80000000 | (int) (d - 2147483648.0);
67 else
68 id = (int) d;
69 return (unsigned) id;
70 }
71