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 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 /* Copyright (c) 1988 AT&T */
28 /* All Rights Reserved */
29
30 /* IEEE recommended functions */
31
32 #pragma weak _finite = finite
33 #pragma weak _fpclass = fpclass
34 #pragma weak _unordered = unordered
35
36 #include "lint.h"
37 #include <values.h>
38 #include "fpparts.h"
39
40 #define P754_NOFAULT 1 /* avoid generating extra code */
41 #include <ieeefp.h>
42
43 /*
44 * FINITE(X)
45 * finite(x) returns 1 if x > -inf and x < +inf and 0 otherwise
46 * NaN returns 0
47 */
48
49 int
finite(double x)50 finite(double x)
51 {
52 return ((EXPONENT(x) != MAXEXP));
53 }
54
55 /*
56 * UNORDERED(x,y)
57 * unordered(x,y) returns 1 if x is unordered with y, otherwise
58 * it returns 0; x is unordered with y if either x or y is NAN
59 */
60
61 int
unordered(double x,double y)62 unordered(double x, double y)
63 {
64 if ((EXPONENT(x) == MAXEXP) && (HIFRACTION(x) || LOFRACTION(x)))
65 return (1);
66 if ((EXPONENT(y) == MAXEXP) && (HIFRACTION(y) || LOFRACTION(y)))
67 return (1);
68 return (0);
69 }
70
71 /*
72 * FPCLASS(X)
73 * fpclass(x) returns the floating point class x belongs to
74 */
75
76 fpclass_t
fpclass(double x)77 fpclass(double x)
78 {
79 int sign, exp;
80
81 exp = EXPONENT(x);
82 sign = SIGNBIT(x);
83 if (exp == 0) { /* de-normal or zero */
84 if (HIFRACTION(x) || LOFRACTION(x)) /* de-normal */
85 return (sign ? FP_NDENORM : FP_PDENORM);
86 else
87 return (sign ? FP_NZERO : FP_PZERO);
88 }
89 if (exp == MAXEXP) { /* infinity or NaN */
90 if ((HIFRACTION(x) == 0) && (LOFRACTION(x) == 0)) /* infinity */
91 return (sign ? FP_NINF : FP_PINF);
92 else
93 if (QNANBIT(x))
94 /* hi-bit of mantissa set - quiet nan */
95 return (FP_QNAN);
96 else return (FP_SNAN);
97 }
98 /* if we reach here we have non-zero normalized number */
99 return (sign ? FP_NNORM : FP_PNORM);
100 }
101