s_fmaxf.c revision 131320
1133362Sobrien/*- 2133362Sobrien * Copyright (c) 2004 David Schultz <das@FreeBSD.ORG> 3133362Sobrien * All rights reserved. 4133365Sobrien * 5133362Sobrien * Redistribution and use in source and binary forms, with or without 6133362Sobrien * modification, are permitted provided that the following conditions 7133362Sobrien * are met: 8195767Skensmith * 1. Redistributions of source code must retain the above copyright 9152285Sru * notice, this list of conditions and the following disclaimer. 10152285Sru * 2. Redistributions in binary form must reproduce the above copyright 11133362Sobrien * notice, this list of conditions and the following disclaimer in the 12133362Sobrien * documentation and/or other materials provided with the distribution. 13191771Sobrien * 14191771Sobrien * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15191771Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16137887Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17133362Sobrien * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18133370Sobrien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19133362Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20159769Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21133362Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22133362Sobrien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23186693Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24133362Sobrien * SUCH DAMAGE. 25186693Sobrien */ 26133362Sobrien 27133362Sobrien#include <sys/cdefs.h> 28133362Sobrien__FBSDID("$FreeBSD: head/lib/msun/src/s_fmaxf.c 131320 2004-06-30 07:04:01Z das $"); 29133362Sobrien 30133362Sobrien#include <math.h> 31133362Sobrien 32133362Sobrien#include "fpmath.h" 33133362Sobrien 34133362Sobrienfloat 35133362Sobrienfmaxf(float x, float y) 36133362Sobrien{ 37133362Sobrien union IEEEf2bits u[2]; 38133362Sobrien 39133362Sobrien u[0].f = x; 40133362Sobrien u[1].f = y; 41133362Sobrien 42133362Sobrien /* Check for NaNs to avoid raising spurious exceptions. */ 43133362Sobrien if (u[0].bits.exp == 255 && u[0].bits.man != 0) 44136681Sru return (y); 45136681Sru if (u[1].bits.exp == 255 && u[1].bits.man != 0) 46133362Sobrien return (x); 47133362Sobrien 48133362Sobrien /* Handle comparisons of signed zeroes. */ 49133362Sobrien if (u[0].bits.sign != u[1].bits.sign) 50133362Sobrien return (u[u[0].bits.sign].f); 51133362Sobrien 52133362Sobrien return (x > y ? x : y); 53133362Sobrien} 54133362Sobrien