Mail Archives: djgpp-workers/2003/08/29/12:53:20
Here's what I'm going to commit soon. Comments?
Index: djgpp/include/math.h
===================================================================
RCS file: /cvs/djgpp/djgpp/include/math.h,v
retrieving revision 1.8
diff -p -u -r1.8 math.h
--- djgpp/include/math.h 22 Mar 2003 11:59:57 -0000 1.8
+++ djgpp/include/math.h 29 Aug 2003 16:43:22 -0000
@@ -56,6 +56,29 @@ extern long double __dj_huge_vall;
extern float __dj_nan;
#define NAN __dj_nan
+#define FP_INFINITE 0
+#define FP_NAN 1
+#define FP_NORMAL 2
+#define FP_SUBNORMAL 3
+#define FP_ZERO 4
+/* Extended with Unnormals (for long doubles). */
+#define FP_UNNORMAL 1024
+
+#define fpclassify(x) ((sizeof(x)==sizeof(float))? __fpclassifyf(x) : \
+ (sizeof(x)==sizeof(double))? __fpclassifyd(x) : \
+ __fpclassifyld(x))
+
+#define isfinite(x) (fpclassify(x)==FP_NORMAL || \
+ fpclassify(x)==FP_SUBNORMAL || \
+ fpclassify(x)==FP_ZERO)
+#define isinf(x) (fpclassify(x)==FP_INFINITE)
+#define isnan(x) (fpclassify(x)==FP_NAN)
+#define isnormal(x) (fpclassify(x)==FP_NORMAL)
+
+int __fpclassifyf(float) __attribute__((const));
+int __fpclassifyd(double) __attribute__((const));
+int __fpclassifyld(long double) __attribute__((const));
+
#endif /* (__STDC_VERSION__ >= 199901L) || !__STRICT_ANSI__ */
#ifndef __STRICT_ANSI__
@@ -111,8 +134,6 @@ struct exception {
extern double erf(double);
extern double erfc(double);
extern double gamma(double);
-extern int isinf(double);
-extern int isnan(double);
extern int finite(double);
extern double j0(double);
extern double j1(double);
Index: djgpp/src/docs/kb/wc204.txi
===================================================================
RCS file: /cvs/djgpp/djgpp/src/docs/kb/wc204.txi,v
retrieving revision 1.159
diff -p -u -r1.159 wc204.txi
--- djgpp/src/docs/kb/wc204.txi 9 Aug 2003 12:32:11 -0000 1.159
+++ djgpp/src/docs/kb/wc204.txi 29 Aug 2003 16:43:28 -0000
@@ -1000,3 +1000,11 @@ when comparing the truenames of existing
Fix a bug in moving directories into themselves. Previously
@code{rename} failed to detect that a subdirectory was being moved
into itself, when the current directory was a short filename.
+
+@findex fpclassify AT r{ added}
+@findex __fpclassifyf AT r{ added}
+@findex __fpclassifyd AT r{ added}
+@findex __fpclassifyld AT r{ added}
+The C99 macro @code{fpclassify} and the supporting functions
+@code{__fpclassifyf}, @code{__fpclassifyd} and @code{__fpclassifyld}
+were added.
Index: djgpp/src/libc/c99/math/fp-asm.sed
===================================================================
RCS file: djgpp/src/libc/c99/math/fp-asm.sed
diff -N djgpp/src/libc/c99/math/fp-asm.sed
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ djgpp/src/libc/c99/math/fp-asm.sed 29 Aug 2003 16:43:28 -0000
@@ -0,0 +1 @@
+/\#define[ \t]\+FP_/p
Index: djgpp/src/libc/c99/math/fpclass.txh
===================================================================
RCS file: djgpp/src/libc/c99/math/fpclass.txh
diff -N djgpp/src/libc/c99/math/fpclass.txh
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ djgpp/src/libc/c99/math/fpclass.txh 29 Aug 2003 16:43:28 -0000
@@ -0,0 +1,54 @@
+@ignore
+ * File fpclass.txh.
+ *
+ * Copyright (C) 2003 Martin Str@"omberg <ams AT ludd DOT luth DOT se>.
+ *
+ * This software may be used freely so long as this copyright notice is
+ * left intact. There is no warranty on this software.
+ *
+@end ignore
+
+@node fpclassify, math
+@findex fpclassify
+@subheading Syntax
+
+@example
+#include <math.h>
+@end example
+
+@subheading Description
+
+The macro @code{fpclassify} returns the kind of the floating point
+value supplied.
+
+@subheading Return Value
+
+@code{FP_INFINITE}, @code{FP_NAN}, @code{FP_NORMAL},
+@code{FP_SUBNORMAL}, @code{FP_ZERO} or @code{FP_UNNORMAL}.
+
+@subheading Portability
+
+@portability !ansi-c89, ansi-c99
+
+@subheading Example
+
+@example
+float f = 1;
+double d = INFINITY;
+long double ld = NAN;
+
+if( fpclassify(f) != FP_NORMAL )
+@{
+ printf("Something is wrong with the implementation!\n");
+@}
+if( fpclassify(d) != FP_INFINITE )
+@{
+ printf("Something is wrong with the implementation!\n");
+@}
+if( fpclassify(ld) != FP_NAN )
+@{
+ printf("Something is wrong with the implementation!\n");
+@}
+
+@end example
+
Index: djgpp/src/libc/c99/math/fpclassd.S
===================================================================
RCS file: djgpp/src/libc/c99/math/fpclassd.S
diff -N djgpp/src/libc/c99/math/fpclassd.S
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ djgpp/src/libc/c99/math/fpclassd.S 29 Aug 2003 16:43:28 -0000
@@ -0,0 +1,60 @@
+/*
+ * File fpclassd.S.
+ *
+ * Copyright (C) 2003 Martin Str@"omberg <ams AT ludd DOT luth DOT se>.
+ *
+ * This software may be used freely so long as this copyright notice is
+ * left intact. There is no warranty on this software.
+ *
+ */
+
+/*#include <sys/math_def.h>*/
+#include "fp-asm.h"
+
+/*
+ * Bits: 63 (sign), 62-52 (exponent), 51-0 (fraction)
+ * Zero: +/- 0 0
+ * Subnormal +/- 0 !=0
+ * Normal +/- !=0, <0xff any
+ * Infinity: +/- 0xff 0
+ * NaN: any 0xff !=0
+ */
+
+/*
+ * Stack:
+ * 8(%esp): high 32 bits of the double
+ * 4(%esp): low 32 bits of the double
+ * 0(%esp): return address
+ */
+ .globl ___fpclassifyd
+___fpclassifyd:
+ movl 8(%esp), %eax
+ movl %eax, %edx
+ andl $0x7ff00000, %eax
+ jz zero_exponent
+
+ cmpl $0x7ff00000, %eax
+ je all_ones_exponent
+
+ movl $FP_NORMAL, %eax
+ ret
+
+zero_exponent:
+ andl $0xfffff, %edx
+ orl 4(%esp), %edx
+ movl $FP_ZERO, %eax
+ jz zero
+
+ movl $FP_SUBNORMAL, %eax
+zero:
+ ret
+
+all_ones_exponent:
+ andl $0xfffff, %edx
+ orl 4(%esp), %edx
+ movl $FP_INFINITE, %eax
+ jz infinity
+
+ movl $FP_NAN, %eax
+infinity:
+ ret
Index: djgpp/src/libc/c99/math/fpclassd.txh
===================================================================
RCS file: djgpp/src/libc/c99/math/fpclassd.txh
diff -N djgpp/src/libc/c99/math/fpclassd.txh
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ djgpp/src/libc/c99/math/fpclassd.txh 29 Aug 2003 16:43:28 -0000
@@ -0,0 +1,45 @@
+@ignore
+ * File fpclassd.txh.
+ *
+ * Copyright (C) 2003 Martin Str@"omberg <ams AT ludd DOT luth DOT se>.
+ *
+ * This software may be used freely so long as this copyright notice is
+ * left intact. There is no warranty on this software.
+ *
+@end ignore
+
+@node __fpclassifyd, math
+@findex __fpclassifyd
+@subheading Syntax
+
+@example
+#include <math.h>
+
+int __fpclassifyd(double);
+@end example
+
+@subheading Description
+
+Returns the kind of the floating point value supplied. You should use
+the type generic macro @code{fpclassify} (@pxref{fpclassify}) instead
+of this function.
+
+@subheading Return Value
+
+@code{FP_INFINITE}, @code{FP_NAN}, @code{FP_NORMAL},
+@code{FP_SUBNORMAL} or @code{FP_ZERO}.
+
+@subheading Portability
+
+@portability !ansi-c89, ansi-c99
+
+@subheading Example
+
+@example
+if( __fpclassifyd(0.0) != FP_ZERO )
+@{
+ printf("Something is wrong with the implementation!\n");
+@}
+
+@end example
+
Index: djgpp/src/libc/c99/math/fpclassf.S
===================================================================
RCS file: djgpp/src/libc/c99/math/fpclassf.S
diff -N djgpp/src/libc/c99/math/fpclassf.S
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ djgpp/src/libc/c99/math/fpclassf.S 29 Aug 2003 16:43:28 -0000
@@ -0,0 +1,53 @@
+/*
+ * File fpclassf.S.
+ *
+ * Copyright (C) 2003 Martin Str@"omberg <ams AT ludd DOT luth DOT se>.
+ *
+ * This software may be used freely so long as this copyright notice is
+ * left intact. There is no warranty on this software.
+ *
+ */
+
+/*#include <sys/math_def.h>*/
+/*#include <math.h>*/
+#include "fp-asm.h"
+
+/*
+ * Bits: 31 (sign), 30-23 (exponent), 22-0 (fraction)
+ * Zero: +/- 0 0
+ * Subnormal +/- 0 !=0
+ * Normal +/- !=0, <0xff any
+ * Infinity: +/- 0xff 0
+ * NaN: any 0xff !=0
+ */
+
+ .globl ___fpclassifyf
+___fpclassifyf:
+ movl 4(%esp), %eax
+ movl %eax, %edx
+ andl $0x7f800000, %eax
+ jz zero_exponent
+
+ cmpl $0x7f800000, %eax
+ je all_ones_exponent
+
+ movl $FP_NORMAL, %eax
+ ret
+
+zero_exponent:
+ movl $FP_ZERO, %eax
+ testl $0x7fffff, %edx
+ jz zero
+
+ movl $FP_SUBNORMAL, %eax
+zero:
+ ret
+
+all_ones_exponent:
+ movl $FP_INFINITE, %eax
+ testl $0x7fffff, %edx
+ jz infinity
+
+ movl $FP_NAN, %eax
+infinity:
+ ret
Index: djgpp/src/libc/c99/math/fpclassf.txh
===================================================================
RCS file: djgpp/src/libc/c99/math/fpclassf.txh
diff -N djgpp/src/libc/c99/math/fpclassf.txh
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ djgpp/src/libc/c99/math/fpclassf.txh 29 Aug 2003 16:43:28 -0000
@@ -0,0 +1,45 @@
+@ignore
+ * File fpclassf.txh.
+ *
+ * Copyright (C) 2003 Martin Str@"omberg <ams AT ludd DOT luth DOT se>.
+ *
+ * This software may be used freely so long as this copyright notice is
+ * left intact. There is no warranty on this software.
+ *
+@end ignore
+
+@node __fpclassifyf, math
+@findex __fpclassifyf
+@subheading Syntax
+
+@example
+#include <math.h>
+
+int __fpclassifyf(float);
+@end example
+
+@subheading Description
+
+Returns the kind of the floating point value supplied. You should use
+the type generic macro @code{fpclassify} (@pxref{fpclassify}) instead
+of this function.
+
+@subheading Return Value
+
+@code{FP_INFINITE}, @code{FP_NAN}, @code{FP_NORMAL},
+@code{FP_SUBNORMAL} or @code{FP_ZERO}.
+
+@subheading Portability
+
+@portability !ansi-c89, ansi-c99
+
+@subheading Example
+
+@example
+if( __fpclassifyf(0.0F) != FP_ZERO )
+@{
+ printf("Something is wrong with the implementation!\n");
+@}
+
+@end example
+
Index: djgpp/src/libc/c99/math/fpclassl.S
===================================================================
RCS file: djgpp/src/libc/c99/math/fpclassl.S
diff -N djgpp/src/libc/c99/math/fpclassl.S
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ djgpp/src/libc/c99/math/fpclassl.S 29 Aug 2003 16:43:29 -0000
@@ -0,0 +1,72 @@
+/*
+ * File fpclassd.S.
+ *
+ * Copyright (C) 2003 Martin Str@"omberg <ams AT ludd DOT luth DOT se>.
+ *
+ * This software may be used freely so long as this copyright notice is
+ * left intact. There is no warranty on this software.
+ *
+ */
+
+/*#include <sys/math_def.h>*/
+#include "fp-asm.h"
+
+/*
+ * Bits: 79 (sign), 78-64 (exponent), 63 (integer), 62-0 (fraction)
+ * Zero: +/- 0 0 0
+ * Subnormal +/- 0 0 !=0
+ * Normal +/- !=0, <0xff 1 any
+ * Infinity: +/- 0xff 1 0
+ * NaN: any 0xff 1 !=0
+ * Unnormal(1) any 0 1 any
+ * Unnormal(2) any !=0 0 any
+ */
+
+/*
+ * Stack:
+ * 12(%esp): high 16 bits of the long double
+ * 8(%esp): middle 32 bits of the long double
+ * 4(%esp): low 32 bits of the long double
+ * 0(%esp): return address
+ */
+ .globl ___fpclassifyld
+___fpclassifyld:
+ movl 8(%esp), %edx
+ movl 12(%esp), %eax
+ testl $0x80000000, %edx
+ jz no_one_bit
+
+ andl $0x7fffffff, %edx /* Remove integer bit. */
+ andl $0x7fff, %eax
+ jz unnormal
+
+ cmpl $0x7fff, %eax
+ je all_ones_exponent
+
+ movl $FP_NORMAL, %eax
+ ret
+
+no_one_bit:
+ andl $0x7fff, %eax
+ jnz unnormal
+
+ orl 4(%esp), %edx
+ movl $FP_ZERO, %eax
+ jz zero
+
+ movl $FP_SUBNORMAL, %eax
+zero:
+ ret
+
+unnormal:
+ movl $FP_UNNORMAL, %eax
+ ret
+
+all_ones_exponent:
+ orl 4(%esp), %edx
+ movl $FP_INFINITE, %eax
+ jz infinity
+
+ movl $FP_NAN, %eax
+infinity:
+ ret
Index: djgpp/src/libc/c99/math/fpclassl.txh
===================================================================
RCS file: djgpp/src/libc/c99/math/fpclassl.txh
diff -N djgpp/src/libc/c99/math/fpclassl.txh
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ djgpp/src/libc/c99/math/fpclassl.txh 29 Aug 2003 16:43:29 -0000
@@ -0,0 +1,45 @@
+@ignore
+ * File fpclassl.txh.
+ *
+ * Copyright (C) 2003 Martin Str@"omberg <ams AT ludd DOT luth DOT se>.
+ *
+ * This software may be used freely so long as this copyright notice is
+ * left intact. There is no warranty on this software.
+ *
+@end ignore
+
+@node __fpclassifyld, math
+@findex __fpclassifyld
+@subheading Syntax
+
+@example
+#include <math.h>
+
+int __fpclassifyld(long double);
+@end example
+
+@subheading Description
+
+Returns the kind of the floating point value supplied. You should use
+the type generic macro @code{fpclassify} (@pxref{fpclassify}) instead
+of this function.
+
+@subheading Return Value
+
+@code{FP_INFINITE}, @code{FP_NAN}, @code{FP_NORMAL},
+@code{FP_SUBNORMAL}, @code{FP_ZERO} or @code{FP_UNNORMAL}.
+
+@subheading Portability
+
+@portability !ansi-c89, ansi-c99
+
+@subheading Example
+
+@example
+if( __fpclassifyld(0.0L) != FP_ZERO )
+@{
+ printf("Something is wrong with the implementation!\n");
+@}
+
+@end example
+
Index: djgpp/src/libc/c99/math/makefile
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/c99/math/makefile,v
retrieving revision 1.2
diff -p -u -r1.2 makefile
--- djgpp/src/libc/c99/math/makefile 22 Mar 2003 11:59:57 -0000 1.2
+++ djgpp/src/libc/c99/math/makefile 29 Aug 2003 16:43:29 -0000
@@ -4,5 +4,20 @@ TOP=../..
SRC += hugevalf.c
SRC += hugevall.c
SRC += nan.c
+SRC += fpclassf.S
+SRC += fpclassd.S
+SRC += fpclassl.S
include $(TOP)/../makefile.inc
+
+fpclassf.S: fp-asm.h
+
+fpclassd.S: fp-asm.h
+
+fpclassl.S: fp-asm.h
+
+fp-asm.h: fp-asm.sed $(TOP)/../../include/math.h
+ sed -n -f fp-asm.sed $(TOP)/../../include/math.h > fp-asm.h
+
+clean::
+ $(MISC) rm -f fp-asm.h
Index: djgpp/tests/libc/c99/math/makefile
===================================================================
RCS file: /cvs/djgpp/djgpp/tests/libc/c99/math/makefile,v
retrieving revision 1.1
diff -p -u -r1.1 makefile
--- djgpp/tests/libc/c99/math/makefile 22 Mar 2003 12:01:02 -0000 1.1
+++ djgpp/tests/libc/c99/math/makefile 29 Aug 2003 16:43:30 -0000
@@ -1,5 +1,6 @@
TOP=../..
SRC += t-nan.c
+SRC += t-fpclas.c
include $(TOP)/../makefile.inc
Index: djgpp/tests/libc/c99/math/t-fpclas.c
===================================================================
RCS file: djgpp/tests/libc/c99/math/t-fpclas.c
diff -N djgpp/tests/libc/c99/math/t-fpclas.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ djgpp/tests/libc/c99/math/t-fpclas.c 29 Aug 2003 16:43:30 -0000
@@ -0,0 +1,193 @@
+/*
+ * File t-fpclas.c (8.3 of t-fpclassify.c).
+ *
+ * Copyright (C) 2003 Martin Str@"omberg <ams AT ludd DOT luth DOT se>.
+ *
+ * This software may be used freely so long as this copyright notice is
+ * left intact. There is no warranty on this software.
+ *
+ */
+
+#include <math.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <libc/ieee.h>
+
+typedef struct {
+ float_t number; /* Number to test. */
+ int class; /* Which class. */
+} test_float_t;
+
+static const test_float_t tests_float[] =
+{
+ /* Zeros. */
+ { { 0, 0, 0 }, FP_ZERO }, /* 0.0 */
+ { { 0, 0, 1 }, FP_ZERO }, /* -0.0 */
+
+ /* Subnormals aka denormals. */
+ { { 1, 0, 0 }, FP_SUBNORMAL }, /* Very small number. */
+ { { 1, 0, 1 }, FP_SUBNORMAL }, /* Very small -number. */
+
+ /* Normals. */
+ { { 1, 1, 0 }, FP_NORMAL }, /* Small number. */
+ { { 1, 1, 1 }, FP_NORMAL }, /* Small -number. */
+ { { 0xff, 0xfe, 0 }, FP_NORMAL }, /* Big number. */
+ { { 0xff, 0xfe, 1 }, FP_NORMAL }, /* Big -number. */
+
+ /* Infs. */
+ { { 0, 0xff, 0 }, FP_INFINITE }, /* Inf */
+ { { 0, 0xff, 1 }, FP_INFINITE }, /* -Inf */
+
+ /* NaNs. */
+ { { 1, 0xff, 0 }, FP_NAN }, /* SNaN */
+ { { 1, 0xff, 1 }, FP_NAN }, /* -SNaN */
+ { { 0x7fffff, 0xff, 0 }, FP_NAN }, /* QNaN */
+ { { 0x7fffff, 0xff, 1 }, FP_NAN }, /* -QNaN */
+};
+
+static const size_t n_tests_float = sizeof(tests_float) / sizeof(tests_float[0]);
+
+typedef struct {
+ double_t number; /* Number to test. */
+ int class; /* Which class. */
+} test_double_t;
+
+static const test_double_t tests_double[] =
+{
+ /* Zeros. */
+ { { 0, 0, 0, 0 }, FP_ZERO }, /* 0.0 */
+ { { 0, 0, 0, 1 }, FP_ZERO }, /* -0.0 */
+
+ /* Subnormals aka denormals. */
+ { { 1, 0, 0, 0 }, FP_SUBNORMAL }, /* Very small number. */
+ { { 1, 0, 0, 1 }, FP_SUBNORMAL }, /* Very small -number. */
+
+ /* Normals. */
+ { { 1, 0, 1, 0 }, FP_NORMAL }, /* Small number. */
+ { { 1, 0, 1, 1 }, FP_NORMAL }, /* Small -number. */
+ { { 0xffffffff, 0x7ffff, 0x7fe, 0 }, FP_NORMAL }, /* Big number. */
+ { { 0xffffffff, 0x7ffff, 0x7fe, 1 }, FP_NORMAL }, /* Big -number. */
+
+ /* Infs. */
+ { { 0, 0, 0x7ff, 0 }, FP_INFINITE }, /* Inf */
+ { { 0, 0, 0x7ff, 1 }, FP_INFINITE }, /* -Inf */
+
+ /* NaNs. */
+ { { 1, 0, 0x7ff, 0 }, FP_NAN }, /* SNaN */
+ { { 1, 0, 0x7ff, 1 }, FP_NAN }, /* -SNaN */
+ { { 0, 0xfffff, 0x7ff, 0 }, FP_NAN }, /* QNaN */
+ { { 0, 0xfffff, 0x7ff, 1 }, FP_NAN }, /* -QNaN */
+};
+
+static const size_t n_tests_double = sizeof(tests_double) / sizeof(tests_double[0]);
+
+typedef struct {
+ long_double_t number; /* Number to test. */
+ int class; /* Which class. */
+} test_long_double_t;
+
+static const test_long_double_t tests_long_double[] =
+{
+ /* Zeros. */
+ { { 0, 0, 0, 0 }, FP_ZERO }, /* 0.0. */
+ { { 0, 0, 0, 1 }, FP_ZERO }, /* -0.0. */
+
+ /* Subnormals aka denormals. */
+ { { 1, 0, 0, 0 }, FP_SUBNORMAL }, /* Subnormal, smallest possible > 0. */
+ { { 1, 0, 0, 1 }, FP_SUBNORMAL }, /* -Subnormal, biggest possible < 0. */
+ { { 0, 1, 0, 0 }, FP_SUBNORMAL }, /* Subnormal. */
+ { { 0, 1, 0, 1 }, FP_SUBNORMAL }, /* -Subnormal. */
+
+ /* Unnormals. */
+ { { 0, 0x80000000, 0, 0 }, FP_UNNORMAL }, /* Unnormal, 0 with integer bit set. */
+ { { 0, 0x80000000, 0, 1 }, FP_UNNORMAL }, /* Unnormal, -0 with integer bit set. */
+ { { 1, 0x80000000, 0, 0 }, FP_UNNORMAL }, /* Unnormal, smallest possible > 0 with integer bit set. */
+ { { 1, 0x80000000, 0, 1 }, FP_UNNORMAL }, /* Unnormal, biggest possible < 0 with integer bit set. */
+ { { 1, 0, 1, 0 }, FP_UNNORMAL }, /* Small number with missing 1. */
+ { { 1, 0, 1, 1 }, FP_UNNORMAL }, /* Small -number with missing 1. */
+ { { 0xffffffff, 0x7fffffff, 0x7ffe, 0 }, FP_UNNORMAL }, /* Big number with missing 1. */
+ { { 0xffffffff, 0x7fffffff, 0x7ffe, 1 }, FP_UNNORMAL }, /* Big -number with missing 1. */
+ { { 0, 0, 0x7fff, 0 }, FP_UNNORMAL }, /* Inf with missing 1. */
+ { { 0, 0, 0x7fff, 1 }, FP_UNNORMAL }, /* -Inf with missing 1. */
+ { { 1, 0, 0x7fff, 0 }, FP_UNNORMAL }, /* SNaN with missing 1 */
+ { { 1, 0, 0x7fff, 1 }, FP_UNNORMAL }, /* -SNaN with missing 1 */
+ { { 0, 0x7fffffff, 0x7fff, 0 }, FP_UNNORMAL }, /* QNaN with missing 1 */
+ { { 0, 0x7fffffff, 0x7fff, 1 }, FP_UNNORMAL }, /* -QNaN with missing 1 */
+
+ /* Normals. */
+ { { 1, 0x80000000, 1, 0 }, FP_NORMAL }, /* Normal, smallest possible > 0. */
+ { { 1, 0x80000000, 1, 1 }, FP_NORMAL }, /* Normal, biggest possible < 0. */
+ { { 0xffffffff, 0xffffffff, 0x7ffe, 0 }, FP_NORMAL }, /* Big number. */
+ { { 0xffffffff, 0xffffffff, 0x7ffe, 1 }, FP_NORMAL }, /* Big -number. */
+
+ /* Infs. */
+ { { 0, 0x80000000, 0x7fff, 0 }, FP_INFINITE }, /* Inf. */
+ { { 0, 0x80000000, 0x7fff, 1 }, FP_INFINITE }, /* -Inf. */
+
+ /* NaNs. */
+ { { 1, 0x80000000, 0x7fff, 0 }, FP_NAN }, /* SNaN */
+ { { 1, 0x80000000, 0x7fff, 1 }, FP_NAN }, /* -SNaN */
+ { { 0, 0xffffffff, 0x7fff, 0 }, FP_NAN }, /* QNaN */
+ { { 0, 0xffffffff, 0x7fff, 1 }, FP_NAN }, /* -QNaN */
+};
+
+static const size_t n_tests_long_double = sizeof(tests_long_double) / sizeof(tests_long_double[0]);
+
+int
+main(void)
+{
+ int result;
+ size_t i;
+
+ printf("FP_ZERO=0x%x, FP_SUBNORMAL=0x%x, FP_NORMAL=0x%x, FP_INFINITE=0x%d,\n"
+ "FP_NAN=0x%x, FP_UNNORMAL=0x%x\n\n",
+ FP_ZERO, FP_SUBNORMAL, FP_NORMAL, FP_INFINITE,
+ FP_NAN, FP_UNNORMAL);
+
+ puts("Float tests:");
+ for(i = 0; i < n_tests_float; i++)
+ {
+ result = fpclassify(*(const float *)(&(tests_float[i].number)));
+ printf("\t%G -> 0x%x: ", *(const float *)(&(tests_float[i].number)), result);
+ if( result == tests_float[i].class )
+ {
+ puts("Ok.");
+ }
+ else
+ {
+ puts("Fail.");
+ }
+ }
+
+ puts("Double tests:");
+ for(i = 0; i < n_tests_double; i++)
+ {
+ result = fpclassify(*(const double *)(&(tests_double[i].number)));
+ printf("\t%G -> 0x%x: ", *(const double *)(&(tests_double[i].number)), result);
+ if( result == tests_double[i].class )
+ {
+ puts("Ok.");
+ }
+ else
+ {
+ puts("Fail.");
+ }
+ }
+
+ puts("Long double tests:");
+ for(i = 0; i < n_tests_long_double; i++)
+ {
+ result = fpclassify(*(const long double *)(&(tests_long_double[i].number)));
+ printf("\t%LG -> 0x%x: ", *(const long double *)(&(tests_long_double[i].number)), result);
+ if( result == tests_long_double[i].class )
+ {
+ puts("Ok.");
+ }
+ else
+ {
+ puts("Fail.");
+ }
+ }
+
+ return(EXIT_SUCCESS);
+}
Right,
MartinS
- Raw text -