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