s_isnan.c revision 275004
1133147Sdas/*- 2133147Sdas * Copyright (c) 2004 David Schultz <das@FreeBSD.ORG> 3133147Sdas * All rights reserved. 42116Sjkh * 5133147Sdas * Redistribution and use in source and binary forms, with or without 6133147Sdas * modification, are permitted provided that the following conditions 7133147Sdas * are met: 8133147Sdas * 1. Redistributions of source code must retain the above copyright 9133147Sdas * notice, this list of conditions and the following disclaimer. 10133147Sdas * 2. Redistributions in binary form must reproduce the above copyright 11133147Sdas * notice, this list of conditions and the following disclaimer in the 12133147Sdas * documentation and/or other materials provided with the distribution. 13133147Sdas * 14133147Sdas * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15133147Sdas * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16133147Sdas * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17133147Sdas * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18133147Sdas * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19133147Sdas * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20133147Sdas * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21133147Sdas * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22133147Sdas * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23133147Sdas * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24133147Sdas * SUCH DAMAGE. 25133147Sdas * 26133147Sdas * $FreeBSD: head/lib/msun/src/s_isnan.c 275004 2014-11-25 03:50:31Z emaste $ 272116Sjkh */ 282116Sjkh 29133147Sdas#include <math.h> 30110769Smike 31133147Sdas#include "fpmath.h" 32133147Sdas 33242879Sdim/* Provided by libc.so */ 34275004Semaste#ifndef PIC 35242879Sdim#undef isnan 36133147Sdasint 37133147Sdasisnan(double d) 38133147Sdas{ 39133147Sdas union IEEEd2bits u; 40133147Sdas 41133147Sdas u.d = d; 42133147Sdas return (u.bits.exp == 2047 && (u.bits.manl != 0 || u.bits.manh != 0)); 43133147Sdas} 44275004Semaste#endif /* !PIC */ 452116Sjkh 46133147Sdasint 47209110Sdas__isnanf(float f) 48133147Sdas{ 49133147Sdas union IEEEf2bits u; 502116Sjkh 51133147Sdas u.f = f; 52133147Sdas return (u.bits.exp == 255 && u.bits.man != 0); 53133147Sdas} 542116Sjkh 55133147Sdasint 56133147Sdas__isnanl(long double e) 57133147Sdas{ 58133147Sdas union IEEEl2bits u; 59110769Smike 60133147Sdas u.e = e; 61133147Sdas mask_nbit_l(u); 62133147Sdas return (u.bits.exp == 32767 && (u.bits.manl != 0 || u.bits.manh != 0)); 632116Sjkh} 64209110Sdas 65209110Sdas__weak_reference(__isnanf, isnanf); 66