s_isnan.c revision 209110
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 209110 2010-06-12 17:32:05Z das $
272116Sjkh */
282116Sjkh
29133147Sdas#include <math.h>
30110769Smike
31133147Sdas#include "fpmath.h"
32133147Sdas
33133147Sdas/* Provided by libc */
34133147Sdas#if 0
35133147Sdasint
36133147Sdasisnan(double d)
37133147Sdas{
38133147Sdas	union IEEEd2bits u;
39133147Sdas
40133147Sdas	u.d = d;
41133147Sdas	return (u.bits.exp == 2047 && (u.bits.manl != 0 || u.bits.manh != 0));
42133147Sdas}
432116Sjkh#endif
442116Sjkh
45133147Sdasint
46209110Sdas__isnanf(float f)
47133147Sdas{
48133147Sdas	union IEEEf2bits u;
492116Sjkh
50133147Sdas	u.f = f;
51133147Sdas	return (u.bits.exp == 255 && u.bits.man != 0);
52133147Sdas}
532116Sjkh
54133147Sdasint
55133147Sdas__isnanl(long double e)
56133147Sdas{
57133147Sdas	union IEEEl2bits u;
58110769Smike
59133147Sdas	u.e = e;
60133147Sdas	mask_nbit_l(u);
61133147Sdas	return (u.bits.exp == 32767 && (u.bits.manl != 0 || u.bits.manh != 0));
622116Sjkh}
63209110Sdas
64209110Sdas__weak_reference(__isnanf, isnanf);
65