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/isinf.c 131898 2004-07-10 15:52:26Z marcel $
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
__isinf(double d)396ff43c94SPeter Avalos __isinf(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
47*0c4f129dSzrj __weak_reference(__isinf, isinf);
48*0c4f129dSzrj
496ff43c94SPeter Avalos int
__isinff(float f)506ff43c94SPeter Avalos __isinff(float f)
516ff43c94SPeter Avalos {
526ff43c94SPeter Avalos union IEEEf2bits u;
536ff43c94SPeter Avalos
546ff43c94SPeter Avalos u.f = f;
556ff43c94SPeter Avalos return (u.bits.exp == 255 && u.bits.man == 0);
566ff43c94SPeter Avalos }
576ff43c94SPeter Avalos
586ff43c94SPeter Avalos int
__isinfl(long double e)596ff43c94SPeter Avalos __isinfl(long double e)
606ff43c94SPeter Avalos {
616ff43c94SPeter Avalos union IEEEl2bits u;
626ff43c94SPeter Avalos
636ff43c94SPeter Avalos u.e = e;
646ff43c94SPeter Avalos mask_nbit_l(u);
656ff43c94SPeter Avalos return (u.bits.exp == 32767 && u.bits.manl == 0 && u.bits.manh == 0);
666ff43c94SPeter Avalos }
67