1131320Sdas/*- 2131320Sdas * Copyright (c) 2004 David Schultz <das@FreeBSD.ORG> 3131320Sdas * All rights reserved. 4131320Sdas * 5131320Sdas * Redistribution and use in source and binary forms, with or without 6131320Sdas * modification, are permitted provided that the following conditions 7131320Sdas * are met: 8131320Sdas * 1. Redistributions of source code must retain the above copyright 9131320Sdas * notice, this list of conditions and the following disclaimer. 10131320Sdas * 2. Redistributions in binary form must reproduce the above copyright 11131320Sdas * notice, this list of conditions and the following disclaimer in the 12131320Sdas * documentation and/or other materials provided with the distribution. 13131320Sdas * 14131320Sdas * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15131320Sdas * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16131320Sdas * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17131320Sdas * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18131320Sdas * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19131320Sdas * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20131320Sdas * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21131320Sdas * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22131320Sdas * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23131320Sdas * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24131320Sdas * SUCH DAMAGE. 25131320Sdas */ 26131320Sdas 27131320Sdas#include <sys/cdefs.h> 28131320Sdas__FBSDID("$FreeBSD: releng/10.2/lib/msun/src/s_fmaxf.c 131320 2004-06-30 07:04:01Z das $"); 29131320Sdas 30131320Sdas#include <math.h> 31131320Sdas 32131320Sdas#include "fpmath.h" 33131320Sdas 34131320Sdasfloat 35131320Sdasfmaxf(float x, float y) 36131320Sdas{ 37131320Sdas union IEEEf2bits u[2]; 38131320Sdas 39131320Sdas u[0].f = x; 40131320Sdas u[1].f = y; 41131320Sdas 42131320Sdas /* Check for NaNs to avoid raising spurious exceptions. */ 43131320Sdas if (u[0].bits.exp == 255 && u[0].bits.man != 0) 44131320Sdas return (y); 45131320Sdas if (u[1].bits.exp == 255 && u[1].bits.man != 0) 46131320Sdas return (x); 47131320Sdas 48131320Sdas /* Handle comparisons of signed zeroes. */ 49131320Sdas if (u[0].bits.sign != u[1].bits.sign) 50131320Sdas return (u[u[0].bits.sign].f); 51131320Sdas 52131320Sdas return (x > y ? x : y); 53131320Sdas} 54