1*96943daaSmartynas /* $OpenBSD: s_fmaxf.c,v 1.3 2013/11/12 18:28:02 martynas Exp $ */
27b36286aSmartynas /*-
37b36286aSmartynas * Copyright (c) 2004 David Schultz <das@FreeBSD.ORG>
47b36286aSmartynas * All rights reserved.
57b36286aSmartynas *
67b36286aSmartynas * Redistribution and use in source and binary forms, with or without
77b36286aSmartynas * modification, are permitted provided that the following conditions
87b36286aSmartynas * are met:
97b36286aSmartynas * 1. Redistributions of source code must retain the above copyright
107b36286aSmartynas * notice, this list of conditions and the following disclaimer.
117b36286aSmartynas * 2. Redistributions in binary form must reproduce the above copyright
127b36286aSmartynas * notice, this list of conditions and the following disclaimer in the
137b36286aSmartynas * documentation and/or other materials provided with the distribution.
147b36286aSmartynas *
157b36286aSmartynas * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
167b36286aSmartynas * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
177b36286aSmartynas * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
187b36286aSmartynas * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
197b36286aSmartynas * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
207b36286aSmartynas * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
217b36286aSmartynas * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
227b36286aSmartynas * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
237b36286aSmartynas * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
247b36286aSmartynas * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
257b36286aSmartynas * SUCH DAMAGE.
267b36286aSmartynas */
277b36286aSmartynas
287b36286aSmartynas #include <math.h>
297b36286aSmartynas
307b36286aSmartynas float
fmaxf(float x,float y)317b36286aSmartynas fmaxf(float x, float y)
327b36286aSmartynas {
337b36286aSmartynas /* Check for NaNs to avoid raising spurious exceptions. */
34f73fafd8Smartynas if (isnan(x))
357b36286aSmartynas return (y);
36f73fafd8Smartynas if (isnan(y))
377b36286aSmartynas return (x);
387b36286aSmartynas
397b36286aSmartynas /* Handle comparisons of signed zeroes. */
40*96943daaSmartynas if (signbit(x) != signbit(y)) {
41f73fafd8Smartynas if (signbit(x))
427b36286aSmartynas return (y);
43f73fafd8Smartynas else
447b36286aSmartynas return (x);
45*96943daaSmartynas }
467b36286aSmartynas
477b36286aSmartynas return (x > y ? x : y);
487b36286aSmartynas }
49