1131852Sdas/*- 2131852Sdas * Copyright (c) 2004 David Schultz <das@FreeBSD.ORG> 3131852Sdas * All rights reserved. 4131852Sdas * 5131852Sdas * Redistribution and use in source and binary forms, with or without 6131852Sdas * modification, are permitted provided that the following conditions 7131852Sdas * are met: 8131852Sdas * 1. Redistributions of source code must retain the above copyright 9131852Sdas * notice, this list of conditions and the following disclaimer. 10131852Sdas * 2. Redistributions in binary form must reproduce the above copyright 11131852Sdas * notice, this list of conditions and the following disclaimer in the 12131852Sdas * documentation and/or other materials provided with the distribution. 13131852Sdas * 14131852Sdas * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15131852Sdas * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16131852Sdas * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17131852Sdas * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18131852Sdas * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19131852Sdas * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20131852Sdas * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21131852Sdas * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22131852Sdas * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23131852Sdas * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24131852Sdas * SUCH DAMAGE. 25131852Sdas * 26131852Sdas * $FreeBSD: releng/10.2/lib/libc/gen/isnan.c 242894 2012-11-11 13:28:04Z dim $ 27131852Sdas */ 28131852Sdas 29131852Sdas#include <math.h> 30131852Sdas 31131852Sdas#include "fpmath.h" 32131852Sdas 33131852Sdas/* 34131852Sdas * XXX These routines belong in libm, but they must remain in libc for 35131852Sdas * binary compat until we can bump libm's major version number. 36242894Sdim * 37242894Sdim * Note this only applies to the dynamic versions of libm and libc, so 38242894Sdim * for the static and profiled versions we stub out the definitions. 39242894Sdim * Otherwise you cannot link statically to libm and libc at the same 40242894Sdim * time, when calling both functions. 41131852Sdas */ 42131852Sdas 43242879Sdim#ifdef PIC 44131852Sdas__weak_reference(__isnan, isnan); 45131852Sdas__weak_reference(__isnanf, isnanf); 46131852Sdas 47131852Sdasint 48131852Sdas__isnan(double d) 49131852Sdas{ 50131852Sdas union IEEEd2bits u; 51131852Sdas 52131852Sdas u.d = d; 53131852Sdas return (u.bits.exp == 2047 && (u.bits.manl != 0 || u.bits.manh != 0)); 54131852Sdas} 55131852Sdas 56131852Sdasint 57131852Sdas__isnanf(float f) 58131852Sdas{ 59131852Sdas union IEEEf2bits u; 60131852Sdas 61131852Sdas u.f = f; 62131852Sdas return (u.bits.exp == 255 && u.bits.man != 0); 63131852Sdas} 64242879Sdim#endif /* PIC */ 65