1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/openenvcore/libm/src/fpclassify.c Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,97 @@
1.4 +/*--------------------------------------------------------------------
1.5 + *© Portions copyright (c) 2006 Nokia Corporation. All rights reserved.
1.6 + *--------------------------------------------------------------------
1.7 +*/
1.8 +/*-
1.9 + * Copyright (c) 2003 Mike Barcroft <mike@FreeBSD.org>
1.10 + * Copyright (c) 2002, 2003 David Schultz <das@FreeBSD.ORG>
1.11 + * All rights reserved.
1.12 + *
1.13 + * Redistribution and use in source and binary forms, with or without
1.14 + * modification, are permitted provided that the following conditions
1.15 + * are met:
1.16 + * 1. Redistributions of source code must retain the above copyright
1.17 + * notice, this list of conditions and the following disclaimer.
1.18 + * 2. Redistributions in binary form must reproduce the above copyright
1.19 + * notice, this list of conditions and the following disclaimer in the
1.20 + * documentation and/or other materials provided with the distribution.
1.21 + *
1.22 + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1.23 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1.24 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1.25 + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1.26 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1.27 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1.28 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1.29 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1.30 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1.31 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
1.32 + * SUCH DAMAGE.
1.33 + *
1.34 + * $FreeBSD: src/lib/libc/gen/fpclassify.c,v 1.2 2005/02/06 03:23:31 das Exp $
1.35 + */
1.36 +
1.37 +#include <sys/endian.h>
1.38 +
1.39 +#include <math.h>
1.40 +#include <stdint.h>
1.41 +
1.42 +#include "fpmath.h"
1.43 +
1.44 +
1.45 +EXPORT_C int __fpclassifyf(float f)
1.46 +{
1.47 + union IEEEf2bits u;
1.48 +
1.49 + u.f = f;
1.50 + if (u.bits.exp == 0) {
1.51 + if (u.bits.man == 0)
1.52 + return (FP_ZERO);
1.53 + return (FP_SUBNORMAL);
1.54 + }
1.55 + if (u.bits.exp == 255) {
1.56 + if (u.bits.man == 0)
1.57 + return (FP_INFINITE);
1.58 + return (FP_NAN);
1.59 + }
1.60 + return (FP_NORMAL);
1.61 +}
1.62 +
1.63 +EXPORT_C int __fpclassifyd(double d)
1.64 +{
1.65 + union IEEEd2bits u;
1.66 +
1.67 + u.d = d;
1.68 + if (u.bits.exp == 0) {
1.69 + if ((u.bits.manl | u.bits.manh) == 0)
1.70 + return (FP_ZERO);
1.71 + return (FP_SUBNORMAL);
1.72 + }
1.73 + if (u.bits.exp == 2047) {
1.74 + if ((u.bits.manl | u.bits.manh) == 0)
1.75 + return (FP_INFINITE);
1.76 + return (FP_NAN);
1.77 + }
1.78 + return (FP_NORMAL);
1.79 +}
1.80 +
1.81 +
1.82 +EXPORT_C int __fpclassifyl(long double e)
1.83 +{
1.84 + union IEEEl2bits u;
1.85 +
1.86 + u.e = e;
1.87 + if (u.bits.exp == 0) {
1.88 + if ((u.bits.manl | u.bits.manh) == 0)
1.89 + return (FP_ZERO);
1.90 + return (FP_SUBNORMAL);
1.91 + }
1.92 + mask_nbit_l(u); /* Mask normalization bit if applicable. */
1.93 + if (u.bits.exp == 32767) {
1.94 + if ((u.bits.manl | u.bits.manh) == 0)
1.95 + return (FP_INFINITE);
1.96 + return (FP_NAN);
1.97 + }
1.98 + return (FP_NORMAL);
1.99 +}
1.100 +