xref: /titanic_50/usr/src/lib/libm/common/m9x/fmaxl.c (revision 1ec68d336ba97cd53f46053ac10401d16014d075)
1*25c28e83SPiotr Jasiukajtis /*
2*25c28e83SPiotr Jasiukajtis  * CDDL HEADER START
3*25c28e83SPiotr Jasiukajtis  *
4*25c28e83SPiotr Jasiukajtis  * The contents of this file are subject to the terms of the
5*25c28e83SPiotr Jasiukajtis  * Common Development and Distribution License (the "License").
6*25c28e83SPiotr Jasiukajtis  * You may not use this file except in compliance with the License.
7*25c28e83SPiotr Jasiukajtis  *
8*25c28e83SPiotr Jasiukajtis  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*25c28e83SPiotr Jasiukajtis  * or http://www.opensolaris.org/os/licensing.
10*25c28e83SPiotr Jasiukajtis  * See the License for the specific language governing permissions
11*25c28e83SPiotr Jasiukajtis  * and limitations under the License.
12*25c28e83SPiotr Jasiukajtis  *
13*25c28e83SPiotr Jasiukajtis  * When distributing Covered Code, include this CDDL HEADER in each
14*25c28e83SPiotr Jasiukajtis  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*25c28e83SPiotr Jasiukajtis  * If applicable, add the following below this CDDL HEADER, with the
16*25c28e83SPiotr Jasiukajtis  * fields enclosed by brackets "[]" replaced with your own identifying
17*25c28e83SPiotr Jasiukajtis  * information: Portions Copyright [yyyy] [name of copyright owner]
18*25c28e83SPiotr Jasiukajtis  *
19*25c28e83SPiotr Jasiukajtis  * CDDL HEADER END
20*25c28e83SPiotr Jasiukajtis  */
21*25c28e83SPiotr Jasiukajtis 
22*25c28e83SPiotr Jasiukajtis /*
23*25c28e83SPiotr Jasiukajtis  * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
24*25c28e83SPiotr Jasiukajtis  */
25*25c28e83SPiotr Jasiukajtis /*
26*25c28e83SPiotr Jasiukajtis  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
27*25c28e83SPiotr Jasiukajtis  * Use is subject to license terms.
28*25c28e83SPiotr Jasiukajtis  */
29*25c28e83SPiotr Jasiukajtis 
30*25c28e83SPiotr Jasiukajtis #pragma weak fmaxl = __fmaxl
31*25c28e83SPiotr Jasiukajtis 
32*25c28e83SPiotr Jasiukajtis #include "libm.h"	/* for isgreaterequal macro */
33*25c28e83SPiotr Jasiukajtis 
34*25c28e83SPiotr Jasiukajtis long double
__fmaxl(long double x,long double y)35*25c28e83SPiotr Jasiukajtis __fmaxl(long double x, long double y) {
36*25c28e83SPiotr Jasiukajtis 	union {
37*25c28e83SPiotr Jasiukajtis #if defined(__sparc)
38*25c28e83SPiotr Jasiukajtis 		unsigned i[4];
39*25c28e83SPiotr Jasiukajtis #elif defined(__x86)
40*25c28e83SPiotr Jasiukajtis 		unsigned i[3];
41*25c28e83SPiotr Jasiukajtis #else
42*25c28e83SPiotr Jasiukajtis #error Unknown architecture
43*25c28e83SPiotr Jasiukajtis #endif
44*25c28e83SPiotr Jasiukajtis 		long double ld;
45*25c28e83SPiotr Jasiukajtis 	} xx, yy;
46*25c28e83SPiotr Jasiukajtis 	unsigned s;
47*25c28e83SPiotr Jasiukajtis 
48*25c28e83SPiotr Jasiukajtis 	/* if y is nan, replace it by x */
49*25c28e83SPiotr Jasiukajtis 	if (y != y)
50*25c28e83SPiotr Jasiukajtis 		y = x;
51*25c28e83SPiotr Jasiukajtis 
52*25c28e83SPiotr Jasiukajtis 	/* if x is nan, replace it by y */
53*25c28e83SPiotr Jasiukajtis 	if (x != x)
54*25c28e83SPiotr Jasiukajtis 		x = y;
55*25c28e83SPiotr Jasiukajtis 
56*25c28e83SPiotr Jasiukajtis 	/* At this point, x and y are either both numeric, or both NaN */
57*25c28e83SPiotr Jasiukajtis 	if (!isnan(x) && !isgreaterequal(x, y))
58*25c28e83SPiotr Jasiukajtis 		x = y;
59*25c28e83SPiotr Jasiukajtis 
60*25c28e83SPiotr Jasiukajtis 	/*
61*25c28e83SPiotr Jasiukajtis 	 * clear the sign of the result if either x or y has its sign clear
62*25c28e83SPiotr Jasiukajtis 	 */
63*25c28e83SPiotr Jasiukajtis 	xx.ld = x;
64*25c28e83SPiotr Jasiukajtis 	yy.ld = y;
65*25c28e83SPiotr Jasiukajtis #if defined(__sparc)
66*25c28e83SPiotr Jasiukajtis 	s = ~(xx.i[0] & yy.i[0]) & 0x80000000;
67*25c28e83SPiotr Jasiukajtis 	xx.i[0] &= ~s;
68*25c28e83SPiotr Jasiukajtis #elif defined(__x86)
69*25c28e83SPiotr Jasiukajtis 	s = ~(xx.i[2] & yy.i[2]) & 0x8000;
70*25c28e83SPiotr Jasiukajtis 	xx.i[2] &= ~s;
71*25c28e83SPiotr Jasiukajtis #else
72*25c28e83SPiotr Jasiukajtis #error Unknown architecture
73*25c28e83SPiotr Jasiukajtis #endif
74*25c28e83SPiotr Jasiukajtis 
75*25c28e83SPiotr Jasiukajtis 	return (xx.ld);
76*25c28e83SPiotr Jasiukajtis }
77