dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / lib / libc / port / fp / finite.c
blobbd40ef1a491aca36b64d6ed646b0d89095eca72d
1 /*
2 * CDDL HEADER START
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.
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.
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]
19 * CDDL HEADER END
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1988 AT&T */
28 /* All Rights Reserved */
30 #pragma ident "%Z%%M% %I% %E% SMI"
32 /* IEEE recommended functions */
34 #pragma weak _finite = finite
35 #pragma weak _fpclass = fpclass
36 #pragma weak _unordered = unordered
38 #include "lint.h"
39 #include <values.h>
40 #include "fpparts.h"
42 #define P754_NOFAULT 1 /* avoid generating extra code */
43 #include <ieeefp.h>
46 * FINITE(X)
47 * finite(x) returns 1 if x > -inf and x < +inf and 0 otherwise
48 * NaN returns 0
51 int
52 finite(double x)
54 return ((EXPONENT(x) != MAXEXP));
58 * UNORDERED(x,y)
59 * unordered(x,y) returns 1 if x is unordered with y, otherwise
60 * it returns 0; x is unordered with y if either x or y is NAN
63 int
64 unordered(double x, double y)
66 if ((EXPONENT(x) == MAXEXP) && (HIFRACTION(x) || LOFRACTION(x)))
67 return (1);
68 if ((EXPONENT(y) == MAXEXP) && (HIFRACTION(y) || LOFRACTION(y)))
69 return (1);
70 return (0);
74 * FPCLASS(X)
75 * fpclass(x) returns the floating point class x belongs to
78 fpclass_t
79 fpclass(double x)
81 int sign, exp;
83 exp = EXPONENT(x);
84 sign = SIGNBIT(x);
85 if (exp == 0) { /* de-normal or zero */
86 if (HIFRACTION(x) || LOFRACTION(x)) /* de-normal */
87 return (sign ? FP_NDENORM : FP_PDENORM);
88 else
89 return (sign ? FP_NZERO : FP_PZERO);
91 if (exp == MAXEXP) { /* infinity or NaN */
92 if ((HIFRACTION(x) == 0) && (LOFRACTION(x) == 0)) /* infinity */
93 return (sign ? FP_NINF : FP_PINF);
94 else
95 if (QNANBIT(x))
96 /* hi-bit of mantissa set - quiet nan */
97 return (FP_QNAN);
98 else return (FP_SNAN);
100 /* if we reach here we have non-zero normalized number */
101 return (sign ? FP_NNORM : FP_PNORM);