xref: /onnv-gate/usr/src/lib/libc/sparc/fp/_Q_set_except.c (revision 6812:febeba71273d)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
280Sstevel@tonic-gate 
29*6812Sraf #include "lint.h"
300Sstevel@tonic-gate #include <sys/ieeefp.h>
310Sstevel@tonic-gate #include <ieeefp.h>
320Sstevel@tonic-gate 
330Sstevel@tonic-gate static const double zero = 0.0, tiny = 1.0e-307, tiny2 = 1.001e-307,
340Sstevel@tonic-gate 	huge = 1.0e300;
350Sstevel@tonic-gate 
360Sstevel@tonic-gate /*
370Sstevel@tonic-gate  * _Q_set_exception(ex) simulates the floating point exceptions indicated by
380Sstevel@tonic-gate  * ex.  This routine is not used by the new quad emulation routines but is
390Sstevel@tonic-gate  * still used by ../crt/_ftoll.c.
400Sstevel@tonic-gate  */
410Sstevel@tonic-gate int
_Q_set_exception(unsigned int ex)420Sstevel@tonic-gate _Q_set_exception(unsigned int ex)
430Sstevel@tonic-gate {
440Sstevel@tonic-gate 	/* LINTED set but not used */
450Sstevel@tonic-gate 	volatile double t;
460Sstevel@tonic-gate 
470Sstevel@tonic-gate 	if (ex == 0)
480Sstevel@tonic-gate 		t = zero - zero;			/* clear cexc */
490Sstevel@tonic-gate 	else {
500Sstevel@tonic-gate 		if ((ex & (1 << fp_invalid)) != 0)
510Sstevel@tonic-gate 			t = zero / zero;
520Sstevel@tonic-gate 		if ((ex & (1 << fp_overflow)) != 0)
530Sstevel@tonic-gate 			t = huge * huge;
540Sstevel@tonic-gate 		if ((ex & (1 << fp_underflow)) != 0) {
550Sstevel@tonic-gate 			if ((ex & (1 << fp_inexact)) != 0 ||
560Sstevel@tonic-gate 			    (fpgetmask() & FP_X_UFL) != 0)
570Sstevel@tonic-gate 				t = tiny * tiny;
580Sstevel@tonic-gate 			else
590Sstevel@tonic-gate 				t = tiny2 - tiny;	/* exact */
600Sstevel@tonic-gate 		}
610Sstevel@tonic-gate 		if ((ex & (1 << fp_division)) != 0)
620Sstevel@tonic-gate 			t = tiny / zero;
630Sstevel@tonic-gate 		if ((ex & (1 << fp_inexact)) != 0)
640Sstevel@tonic-gate 			t = huge + tiny;
650Sstevel@tonic-gate 	}
660Sstevel@tonic-gate 	return (0);
670Sstevel@tonic-gate }
68