xref: /dflybsd-src/lib/libc/gen/isnan.c (revision 0c4f129d375539ed50d86f6d1424eea6f13f52b6)
16ff43c94SPeter Avalos /*-
26ff43c94SPeter Avalos  * Copyright (c) 2004 David Schultz <das@FreeBSD.ORG>
36ff43c94SPeter Avalos  * All rights reserved.
46ff43c94SPeter Avalos  *
56ff43c94SPeter Avalos  * Redistribution and use in source and binary forms, with or without
66ff43c94SPeter Avalos  * modification, are permitted provided that the following conditions
76ff43c94SPeter Avalos  * are met:
86ff43c94SPeter Avalos  * 1. Redistributions of source code must retain the above copyright
96ff43c94SPeter Avalos  *    notice, this list of conditions and the following disclaimer.
106ff43c94SPeter Avalos  * 2. Redistributions in binary form must reproduce the above copyright
116ff43c94SPeter Avalos  *    notice, this list of conditions and the following disclaimer in the
126ff43c94SPeter Avalos  *    documentation and/or other materials provided with the distribution.
136ff43c94SPeter Avalos  *
146ff43c94SPeter Avalos  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
156ff43c94SPeter Avalos  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
166ff43c94SPeter Avalos  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
176ff43c94SPeter Avalos  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
186ff43c94SPeter Avalos  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
196ff43c94SPeter Avalos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
206ff43c94SPeter Avalos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
216ff43c94SPeter Avalos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
226ff43c94SPeter Avalos  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
236ff43c94SPeter Avalos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
246ff43c94SPeter Avalos  * SUCH DAMAGE.
256ff43c94SPeter Avalos  *
266ff43c94SPeter Avalos  * $FreeBSD: head/lib/libc/gen/isnan.c 242894 2012-11-11 13:28:04Z dim $
276ff43c94SPeter Avalos  */
286ff43c94SPeter Avalos 
296ff43c94SPeter Avalos #include <math.h>
306ff43c94SPeter Avalos 
316ff43c94SPeter Avalos #include "fpmath.h"
326ff43c94SPeter Avalos 
336ff43c94SPeter Avalos /*
346ff43c94SPeter Avalos  * XXX These routines belong in libm, but they must remain in libc for
356ff43c94SPeter Avalos  *     binary compat until we can bump libm's major version number.
366ff43c94SPeter Avalos  */
376ff43c94SPeter Avalos 
386ff43c94SPeter Avalos int
__isnan(double d)396ff43c94SPeter Avalos __isnan(double d)
406ff43c94SPeter Avalos {
416ff43c94SPeter Avalos 	union IEEEd2bits u;
426ff43c94SPeter Avalos 
436ff43c94SPeter Avalos 	u.d = d;
446ff43c94SPeter Avalos 	return (u.bits.exp == 2047 && (u.bits.manl != 0 || u.bits.manh != 0));
456ff43c94SPeter Avalos }
466ff43c94SPeter Avalos 
476ff43c94SPeter Avalos int
__isnanf(float f)486ff43c94SPeter Avalos __isnanf(float f)
496ff43c94SPeter Avalos {
506ff43c94SPeter Avalos 	union IEEEf2bits u;
516ff43c94SPeter Avalos 
526ff43c94SPeter Avalos 	u.f = f;
536ff43c94SPeter Avalos 	return (u.bits.exp == 255 && u.bits.man != 0);
546ff43c94SPeter Avalos }
55*0c4f129dSzrj 
56*0c4f129dSzrj __weak_reference(__isnan, isnan);
57*0c4f129dSzrj __weak_reference(__isnanf, isnanf);
58