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: stable/10/lib/msun/src/s_isnan.c 354596 2019-11-10 17:33:10Z dim $
272116Sjkh */
282116Sjkh
29133147Sdas#include <math.h>
30110769Smike
31133147Sdas#include "fpmath.h"
32133147Sdas
33242879Sdim/* Provided by libc.so */
34242879Sdim#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}
44242879Sdim#endif /* !PIC */
452116Sjkh
46354596Sdim/*
47354596Sdim * Because math.h defines __isnanf as an alias for compatibility with glibc and
48354596Sdim * CUDA, we have to undefine it here to avoid redefinition errors.
49354596Sdim */
50354596Sdim#undef __isnanf
51354596Sdim
52133147Sdasint
53209110Sdas__isnanf(float f)
54133147Sdas{
55133147Sdas	union IEEEf2bits u;
562116Sjkh
57133147Sdas	u.f = f;
58133147Sdas	return (u.bits.exp == 255 && u.bits.man != 0);
59133147Sdas}
602116Sjkh
61133147Sdasint
62133147Sdas__isnanl(long double e)
63133147Sdas{
64133147Sdas	union IEEEl2bits u;
65110769Smike
66133147Sdas	u.e = e;
67133147Sdas	mask_nbit_l(u);
68133147Sdas	return (u.bits.exp == 32767 && (u.bits.manl != 0 || u.bits.manh != 0));
692116Sjkh}
70209110Sdas
71209110Sdas__weak_reference(__isnanf, isnanf);
72