10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*6812Sraf * Common Development and Distribution License (the "License").
6*6812Sraf * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
21*6812Sraf
220Sstevel@tonic-gate /*
23*6812Sraf * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
240Sstevel@tonic-gate * Use is subject to license terms.
250Sstevel@tonic-gate */
260Sstevel@tonic-gate
270Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */
280Sstevel@tonic-gate /* All Rights Reserved */
290Sstevel@tonic-gate
30*6812Sraf #pragma ident "%Z%%M% %I% %E% SMI"
310Sstevel@tonic-gate
320Sstevel@tonic-gate /* IEEE recommended functions */
330Sstevel@tonic-gate
34*6812Sraf #pragma weak _finite = finite
35*6812Sraf #pragma weak _fpclass = fpclass
36*6812Sraf #pragma weak _unordered = unordered
370Sstevel@tonic-gate
38*6812Sraf #include "lint.h"
390Sstevel@tonic-gate #include <values.h>
400Sstevel@tonic-gate #include "fpparts.h"
410Sstevel@tonic-gate
420Sstevel@tonic-gate #define P754_NOFAULT 1 /* avoid generating extra code */
430Sstevel@tonic-gate #include <ieeefp.h>
440Sstevel@tonic-gate
450Sstevel@tonic-gate /*
460Sstevel@tonic-gate * FINITE(X)
470Sstevel@tonic-gate * finite(x) returns 1 if x > -inf and x < +inf and 0 otherwise
480Sstevel@tonic-gate * NaN returns 0
490Sstevel@tonic-gate */
500Sstevel@tonic-gate
510Sstevel@tonic-gate int
finite(double x)520Sstevel@tonic-gate finite(double x)
530Sstevel@tonic-gate {
540Sstevel@tonic-gate return ((EXPONENT(x) != MAXEXP));
550Sstevel@tonic-gate }
560Sstevel@tonic-gate
570Sstevel@tonic-gate /*
580Sstevel@tonic-gate * UNORDERED(x,y)
590Sstevel@tonic-gate * unordered(x,y) returns 1 if x is unordered with y, otherwise
600Sstevel@tonic-gate * it returns 0; x is unordered with y if either x or y is NAN
610Sstevel@tonic-gate */
620Sstevel@tonic-gate
630Sstevel@tonic-gate int
unordered(double x,double y)640Sstevel@tonic-gate unordered(double x, double y)
650Sstevel@tonic-gate {
660Sstevel@tonic-gate if ((EXPONENT(x) == MAXEXP) && (HIFRACTION(x) || LOFRACTION(x)))
670Sstevel@tonic-gate return (1);
680Sstevel@tonic-gate if ((EXPONENT(y) == MAXEXP) && (HIFRACTION(y) || LOFRACTION(y)))
690Sstevel@tonic-gate return (1);
700Sstevel@tonic-gate return (0);
710Sstevel@tonic-gate }
720Sstevel@tonic-gate
730Sstevel@tonic-gate /*
740Sstevel@tonic-gate * FPCLASS(X)
750Sstevel@tonic-gate * fpclass(x) returns the floating point class x belongs to
760Sstevel@tonic-gate */
770Sstevel@tonic-gate
780Sstevel@tonic-gate fpclass_t
fpclass(double x)790Sstevel@tonic-gate fpclass(double x)
800Sstevel@tonic-gate {
810Sstevel@tonic-gate int sign, exp;
820Sstevel@tonic-gate
830Sstevel@tonic-gate exp = EXPONENT(x);
840Sstevel@tonic-gate sign = SIGNBIT(x);
850Sstevel@tonic-gate if (exp == 0) { /* de-normal or zero */
860Sstevel@tonic-gate if (HIFRACTION(x) || LOFRACTION(x)) /* de-normal */
870Sstevel@tonic-gate return (sign ? FP_NDENORM : FP_PDENORM);
880Sstevel@tonic-gate else
890Sstevel@tonic-gate return (sign ? FP_NZERO : FP_PZERO);
900Sstevel@tonic-gate }
910Sstevel@tonic-gate if (exp == MAXEXP) { /* infinity or NaN */
920Sstevel@tonic-gate if ((HIFRACTION(x) == 0) && (LOFRACTION(x) == 0)) /* infinity */
930Sstevel@tonic-gate return (sign ? FP_NINF : FP_PINF);
940Sstevel@tonic-gate else
950Sstevel@tonic-gate if (QNANBIT(x))
960Sstevel@tonic-gate /* hi-bit of mantissa set - quiet nan */
970Sstevel@tonic-gate return (FP_QNAN);
980Sstevel@tonic-gate else return (FP_SNAN);
990Sstevel@tonic-gate }
1000Sstevel@tonic-gate /* if we reach here we have non-zero normalized number */
1010Sstevel@tonic-gate return (sign ? FP_NNORM : FP_PNORM);
1020Sstevel@tonic-gate }
103