1*96943daaSmartynas /* $OpenBSD: s_fmaxl.c,v 1.2 2013/11/12 18:28:02 martynas Exp $ */
2390c8400Smartynas /*-
3390c8400Smartynas * Copyright (c) 2004 David Schultz <das@FreeBSD.ORG>
4390c8400Smartynas * All rights reserved.
5390c8400Smartynas *
6390c8400Smartynas * Redistribution and use in source and binary forms, with or without
7390c8400Smartynas * modification, are permitted provided that the following conditions
8390c8400Smartynas * are met:
9390c8400Smartynas * 1. Redistributions of source code must retain the above copyright
10390c8400Smartynas * notice, this list of conditions and the following disclaimer.
11390c8400Smartynas * 2. Redistributions in binary form must reproduce the above copyright
12390c8400Smartynas * notice, this list of conditions and the following disclaimer in the
13390c8400Smartynas * documentation and/or other materials provided with the distribution.
14390c8400Smartynas *
15390c8400Smartynas * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16390c8400Smartynas * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17390c8400Smartynas * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18390c8400Smartynas * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19390c8400Smartynas * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20390c8400Smartynas * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21390c8400Smartynas * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22390c8400Smartynas * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23390c8400Smartynas * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24390c8400Smartynas * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25390c8400Smartynas * SUCH DAMAGE.
26390c8400Smartynas */
27390c8400Smartynas
28390c8400Smartynas #include <math.h>
29390c8400Smartynas
30390c8400Smartynas long double
fmaxl(long double x,long double y)31390c8400Smartynas fmaxl(long double x, long double y)
32390c8400Smartynas {
33390c8400Smartynas /* Check for NaNs to avoid raising spurious exceptions. */
34390c8400Smartynas if (isnan(x))
35390c8400Smartynas return (y);
36390c8400Smartynas if (isnan(y))
37390c8400Smartynas return (x);
38390c8400Smartynas
39390c8400Smartynas /* Handle comparisons of signed zeroes. */
40*96943daaSmartynas if (signbit(x) != signbit(y)) {
41390c8400Smartynas if (signbit(x))
42390c8400Smartynas return (y);
43390c8400Smartynas else
44390c8400Smartynas return (x);
45*96943daaSmartynas }
46390c8400Smartynas
47390c8400Smartynas return (x > y ? x : y);
48390c8400Smartynas }
49