Mail Archives: djgpp-workers/2013/10/19/07:44:13
X-Authentication-Warning: | delorie.com: mail set sender to djgpp-workers-bounces using -f
|
X-Recipient: | djgpp-workers AT delorie DOT com
|
Message-ID: | <52626FC1.9010706@gmx.de>
|
Date: | Sat, 19 Oct 2013 13:40:49 +0200
|
From: | Juan Manuel Guerrero <juan DOT guerrero AT gmx DOT de>
|
User-Agent: | Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121025 Thunderbird/16.0.2
|
MIME-Version: | 1.0
|
To: | djgpp-workers AT delorie DOT com
|
Subject: | Implementation of the [l]lround[f|l] family of functions
|
X-Provags-ID: | V03:K0:ayy+zvO+x5rM7D3uGEh62YJC4Td5h1rIGN96/4nnFbVp3KKaeCa
|
| rbRPXOewW9so7yy7SorILTk2DupEOxoghGBhEXZ6ygZsHYFENR4MYCxFUXd/wHNDnOleJyx
|
| zFznw6KI/XoQBrlWFKVtUNNDefHK4cyArLMl7psqAgA16wJpDGTxB39ZZzg3lXp90FI6DVf
|
| et+RCSWNnuORc69BvyBnw==
|
Reply-To: | djgpp-workers AT delorie DOT com
|
Below is a patch that shall provide the implementation of the [l]lround[f|l]
family of functions for libm.a. Some test cases have been added. I have
compiled and tested the code with gcc473 and with djcross-gcc481.
As usual suggestions, objections and comments are welcome.
Regards,
Juan M. Guerrero
2013-10-19 Juan Manuel Guerrero <juan DOT guerrero AT gmx DOT de>
* djgpp/src/docs/kb/wc204.txi: Info about [l]lround[f|l] family of functions added.
2013-10-06 Juan Manuel Guerrero <juan DOT guerrero AT gmx DOT de>
* djgpp/src/libm/math/lroundl.c: Implementation of lroundl.
* djgpp/src/libm/math/llroundl.c: Implementation of llroundl.
* djgpp/src/libm/math/makefile: [l]lroundl added to goal list.
* djgpp/tests/cygnus/t-llroundl.c: Check for llroundl.
* djgpp/tests/cygnus/t-lroundl.c: Check for lroundl.
* djgpp/tests/cygnus/makefile: [l]lroundl added to goal list.
2013-10-03 Juan Manuel Guerrero <juan DOT guerrero AT gmx DOT de>
* djgpp/src/libm/math/lround.c: Implementation of lround.
* djgpp/src/libm/math/llround.c: Implementation of llround.
* djgpp/src/libm/math/makefile: [l]lround added to goal list.
* djgpp/tests/cygnus/t-llround.c: Check for llround.
* djgpp/tests/cygnus/t-lround.c: Check for lround.
* djgpp/tests/cygnus/makefile: [l]lround added to goal list.
2013-10-02 Juan Manuel Guerrero <juan DOT guerrero AT gmx DOT de>
* djgpp/include/math.h: Prototype of [l]lround[f|l] added.
* djgpp/include/libm/math.h: Prototype of [l]lround[f|l] added.
* djgpp/src/libm/math/lroundf.c: Implementation of lroundf.
* djgpp/src/libm/math/llroundf.c: Implementation of llroundf.
* djgpp/src/libm/math/makefile: [l]lroundf added to goal list.
* djgpp/tests/cygnus/t-lroundf.c: Check for lroundf.
* djgpp/tests/cygnus/makefile: lroundf added to goal list.
diff -aprNU5 djgpp.orig/include/libm/math.h djgpp/include/libm/math.h
--- djgpp.orig/include/libm/math.h 2013-10-14 22:37:58 +0100
+++ djgpp/include/libm/math.h 2013-10-14 22:40:02 +0100
@@ -162,10 +162,16 @@ extern long long int llrintf __P((float)
extern long long int llrint __P((double));
extern long long int llrintl __P((long double));
extern long int lrintf __P((float));
extern long int lrint __P((double));
extern long int lrintl __P((long double));
+extern long long int llroundf __P((float));
+extern long long int llround __P((double));
+extern long long int llroundl __P((long double));
+extern long int lroundf __P((float));
+extern long int lround __P((double));
+extern long int lroundl __P((long double));
extern float roundf __P((float));
extern double round __P((double));
extern long double roundl __P((long double));
extern float truncf __P((float));
extern double trunc __P((double));
diff -aprNU5 djgpp.orig/include/math.h djgpp/include/math.h
--- djgpp.orig/include/math.h 2013-10-14 22:37:58 +0100
+++ djgpp/include/math.h 2013-10-14 22:40:02 +0100
@@ -195,10 +195,14 @@ extern long int lrint(double);
extern long int lrintl(long double);
extern long long int llrint(double);
extern long long int llrintl(long double);
extern double round(double);
extern long double roundl(long double);
+extern long int lround(double);
+extern long int lroundl(long double);
+extern long long int llround(double);
+extern long long int llroundl(long double);
extern float erff(float);
extern float erfcf(float);
extern float hypotf(float, float);
extern float lgammaf(float);
extern float acoshf(float);
@@ -217,10 +221,12 @@ extern float expm1f(float);
extern float log1pf(float);
extern float truncf(float);
extern long int lrintf(float);
extern long long int llrintf(float);
extern float roundf(float);
+extern long int lroundf(float);
+extern long long int llroundf(float);
/* End libm.a. */
#endif /* (__STDC_VERSION__ >= 199901L) || !__STRICT_ANSI__ */
diff -aprNU5 djgpp.orig/src/docs/kb/wc204.txi djgpp/src/docs/kb/wc204.txi
--- djgpp.orig/src/docs/kb/wc204.txi 2013-10-14 22:37:58 +0100
+++ djgpp/src/docs/kb/wc204.txi 2013-10-19 12:39:24 +0100
@@ -1327,5 +1327,16 @@ in @file{libc.a} and one accurate in @fi
@findex roundf AT r{ added}
@findex round AT r{ added}
@findex roundl AT r{ added}
The @acronym{C99} functions @code{roundf}, @code{round} and @code{roundl} were added
to comply with the @acronym{C99} standard.
+
+@cindex @acronym{C99} compliance, @code{math.h}
+@findex lroundf AT r{ added}
+@findex lround AT r{ added}
+@findex lroundl AT r{ added}
+@findex llroundf AT r{ added}
+@findex llround AT r{ added}
+@findex llroundl AT r{ added}
+The @acronym{C99} functions @code{lroundf}, @code{lround}, @code{lroundl}, @code{llroundf},
+@code{llround} and @code{llroundl} were added to comply with the @acronym{C99} standard.
+These functions are available in two versions.
diff -aprNU5 djgpp.orig/src/libm/math/llround.c djgpp/src/libm/math/llround.c
--- djgpp.orig/src/libm/math/llround.c 1970-01-01 01:00:00 +0100
+++ djgpp/src/libm/math/llround.c 2013-10-17 00:14:46 +0100
@@ -0,0 +1,111 @@
+/* Copyright (C) 2013 DJ Delorie, see COPYING.DJ for details */
+
+/*
+<<llround>>, <<llroundf>>, <<llroundl>>--round to integer, to nearest
+INDEX
+ llround
+INDEX
+ llroundf
+INDEX
+ llroundl
+
+ANSI_SYNOPSIS
+ #include <math.h>
+ long long int llround(double <[x]>);
+ long long int llroundf(float <[x]>);
+ long long int llroundl(long double <[x]>);
+
+DESCRIPTION
+ The <<llround>>, <<llroundl>> and <<llroundl>> functions round their
+ argument to the nearest integer value, rounding halfway cases away from
+ zero, regardless of the current rounding direction. If the rounded
+ value is outside the range of the return type, the numeric result is
+ unspecified (depending upon the floating-point implementation, not the
+ library). A range error may occur if the magnitude of x is too large.
+
+RETURNS
+ <[x]> rounded to an integral value as an integer.
+
+SEEALSO
+ See the <<round>> functions for the return being the same floating-point
+ type as the argument. See also <<llrint>>.
+
+PORTABILITY
+ANSI C, POSIX
+
+*/
+
+#include <stdint.h>
+#include <math.h>
+#include <libc/ieee.h>
+
+#if defined (__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8))
+# define __gnuc_extension__ __extension__
+#else
+# define __gnuc_extension__
+#endif
+
+#define DOUBLE_BIAS (0x3FFU)
+#define BIN_DIGITS_IN_FRACTION (52) /* Amount of binary digits in fraction part of mantissa. */
+#define BIN_DIGITS_IN_MANTISSAH (20) /* Amount of binary digits in msw of the fraction part of mantissa. */
+#define BIN_DIGITS_IN_MANTISSAL (BIN_DIGITS_IN_FRACTION - BIN_DIGITS_IN_MANTISSAH)
+#define ALL_DIGITS_ARE_SIGNIFICANT(exp) ((exp) > (BIN_DIGITS_IN_FRACTION - 1))
+#define NO_SIGNIFICANT_DIGITS_IN_MANTISSAL(exp) ((exp) < BIN_DIGITS_IN_MANTISSAH)
+#define MAGNITUDE_IS_TOO_LARGE(exp) ((exp) > (int)(sizeof(long long int) * 8) - 2)
+#define MAGNITUDE_IS_LESS_THAN_ONE(exp) ((exp) < 0)
+#define MAGNITUDE_IS_LESS_THAN_ONE_HALF(exp) ((exp) < -1)
+
+#define ROUND_MANTISSAH_TO_INTEGER(num, unbiased_exponent) ((long long int)((((uint32_t)(num).dt.mantissah | 0x00100000UL) + (0x0080000UL >> (unbiased_exponent))) >> (BIN_DIGITS_IN_MANTISSAH - (unbiased_exponent))))
+
+#define CONVERT_MANTISSA_TO_INTEGER(num, unbiased_exponent) ((long long int)(((((uint64_t)(num).dt.mantissah | 0x00100000UL) << BIN_DIGITS_IN_MANTISSAL) | (uint64_t)(num).dt.mantissal) << ((unbiased_exponent) - BIN_DIGITS_IN_FRACTION)))
+#define ROUND_MANTISSA_TO_INTEGER(num, unbiased_exponent) \
+(__gnuc_extension__ \
+ ({ \
+ uint32_t rounded_mantissal = (uint32_t)(num).dt.mantissal + (0x80000000UL >> ((unbiased_exponent) - BIN_DIGITS_IN_MANTISSAH)); \
+ if (result = ((long long int)(num).dt.mantissah | 0x00100000UL), rounded_mantissal < (num).dt.mantissal) result++; \
+ if ((unbiased_exponent) > BIN_DIGITS_IN_MANTISSAH) \
+ result = result << ((unbiased_exponent) - BIN_DIGITS_IN_MANTISSAH) | rounded_mantissal >> (BIN_DIGITS_IN_FRACTION - (unbiased_exponent)); \
+ (long long int)result; \
+ }) \
+)
+
+
+#ifdef __STDC__
+long long int
+llround(double x)
+#else
+long long int
+llround(x)
+double x;
+#endif
+{
+ _double_union_t ieee_value;
+ int unbiased_exponent, sign;
+ long long int result;
+
+
+ ieee_value.d = x;
+ unbiased_exponent = ieee_value.dt.exponent - DOUBLE_BIAS;
+ sign = ieee_value.dt.sign;
+
+ if (MAGNITUDE_IS_TOO_LARGE(unbiased_exponent)) /* The number is too large. */
+ return (long long int)x; /* It is left implementation defined what happens. */
+ else if (NO_SIGNIFICANT_DIGITS_IN_MANTISSAL(unbiased_exponent))
+ {
+ if (MAGNITUDE_IS_LESS_THAN_ONE(unbiased_exponent))
+ result = MAGNITUDE_IS_LESS_THAN_ONE_HALF(unbiased_exponent) ? 0 : 1;
+ else
+ result = ROUND_MANTISSAH_TO_INTEGER(ieee_value, unbiased_exponent);
+
+ return sign ? -result : result;
+ }
+ else
+ {
+ if (ALL_DIGITS_ARE_SIGNIFICANT(unbiased_exponent))
+ result = CONVERT_MANTISSA_TO_INTEGER(ieee_value, unbiased_exponent); /* >= 2^52 is already an exact integer iff long long int is 64 bit. */
+ else
+ result = ROUND_MANTISSA_TO_INTEGER(ieee_value, unbiased_exponent);
+
+ return sign ? -result : result;
+ }
+}
diff -aprNU5 djgpp.orig/src/libm/math/llroundf.c djgpp/src/libm/math/llroundf.c
--- djgpp.orig/src/libm/math/llroundf.c 1970-01-01 01:00:00 +0100
+++ djgpp/src/libm/math/llroundf.c 2013-10-16 22:34:56 +0100
@@ -0,0 +1,47 @@
+/* Copyright (C) 2013 DJ Delorie, see COPYING.DJ for details */
+
+#include <stdint.h>
+#include <math.h>
+#include <libc/ieee.h>
+
+#define FLOAT_BIAS (0x7FU)
+#define BIN_DIGITS_IN_FRACTION (23) /* Amount of binary digits in fraction part of mantissa. */
+#define MAGNITUDE_IS_TOO_LARGE(exp) ((exp) > (int)(sizeof(long long int) * 8) - 2)
+#define MAGNITUDE_IS_LESS_THAN_ONE(exp) ((exp) < 0)
+#define MAGNITUDE_IS_LESS_THAN_ONE_HALF(exp) ((exp) < -1)
+#define CONVERT_MANTISSA_TO_INTEGER(num, unbiased_exponent) ((long long int)((uint32_t)(num).ft.mantissa | 0x00800000UL) << ((unbiased_exponent) - BIN_DIGITS_IN_FRACTION))
+#define ROUND_MANTISSA_TO_INTEGER(num, unbiased_exponent) ((long long int)((((uint32_t)(num).ft.mantissa | 0x00800000UL) + (0x00400000UL >> (unbiased_exponent))) >> (BIN_DIGITS_IN_FRACTION - (unbiased_exponent))))
+
+
+#ifdef __STDC__
+long long int
+llroundf(float x)
+#else
+long long int
+llroundf(x)
+float x;
+#endif
+{
+ _float_union_t ieee_value;
+ int unbiased_exponent, sign;
+ long long int result;
+
+
+ ieee_value.f = x;
+ unbiased_exponent = ieee_value.ft.exponent - FLOAT_BIAS;
+ sign = ieee_value.ft.sign;
+
+ if (MAGNITUDE_IS_TOO_LARGE(unbiased_exponent)) /* The number is too large. */
+ return (long long int)x; /* It is left implementation defined what happens. */
+ else
+ {
+ if (MAGNITUDE_IS_LESS_THAN_ONE(unbiased_exponent))
+ result = MAGNITUDE_IS_LESS_THAN_ONE_HALF(unbiased_exponent) ? 0 : 1;
+ else if (unbiased_exponent > (BIN_DIGITS_IN_FRACTION - 1))
+ result = CONVERT_MANTISSA_TO_INTEGER(ieee_value, unbiased_exponent); /* >= 2^23 is already an exact integer. */
+ else
+ result = ROUND_MANTISSA_TO_INTEGER(ieee_value, unbiased_exponent);
+
+ return sign ? -result : result;
+ }
+}
diff -aprNU5 djgpp.orig/src/libm/math/llroundl.c djgpp/src/libm/math/llroundl.c
--- djgpp.orig/src/libm/math/llroundl.c 1970-01-01 01:00:00 +0100
+++ djgpp/src/libm/math/llroundl.c 2013-10-19 11:58:36 +0100
@@ -0,0 +1,90 @@
+/* Copyright (C) 2013 DJ Delorie, see COPYING.DJ for details */
+
+#include <stdint.h>
+#include <math.h>
+#include <libc/ieee.h>
+
+#if defined (__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8))
+# define __gnuc_extension__ __extension__
+#else
+# define __gnuc_extension__
+#endif
+
+#define LONG_DOUBLE_BIAS (0x3FFFU)
+#define BIN_DIGITS_IN_FRACTION (63) /* Amount of binary digits in fraction part of mantissa. */
+#define BIN_DIGITS_IN_MANTISSAH (31) /* Amount of binary digits in msw of the fraction part of mantissa. */
+#define BIN_DIGITS_IN_MANTISSAL (BIN_DIGITS_IN_FRACTION - BIN_DIGITS_IN_MANTISSAH)
+#define ALL_DIGITS_ARE_SIGNIFICANT(exp) ((exp) > (BIN_DIGITS_IN_FRACTION - 1))
+#define NO_SIGNIFICANT_DIGITS_IN_MANTISSAL(exp) ((exp) < BIN_DIGITS_IN_MANTISSAH)
+#define MAGNITUDE_IS_TOO_LARGE(exp) ((exp) > (int)(sizeof(long long int) * 8) - 2)
+#define MAGNITUDE_IS_LESS_THAN_ONE(exp) ((exp) < 0)
+#define MAGNITUDE_IS_LESS_THAN_ONE_HALF(exp) ((exp) < -1)
+
+#define CARRY_INTO_INTEGER_PART(x) ((x) & 0x100000000ULL)
+#define ROUND_MANTISSAH_TO_INTEGER(num, unbiased_exponent) \
+(__gnuc_extension__ \
+ ({ \
+ uint64_t rounded_mantissah = (uint64_t)(num).ldt.mantissah + (0x40000000ULL >> (unbiased_exponent)); \
+ if (CARRY_INTO_INTEGER_PART(rounded_mantissah)) \
+ { \
+ rounded_mantissah >>= 1; \
+ unbiased_exponent++; \
+ } \
+ (long long int)(rounded_mantissah >> (BIN_DIGITS_IN_MANTISSAH - (unbiased_exponent))); \
+ }) \
+)
+
+#define SHIFT_LEFT_MANTISSAH(num, unbiased_exponent) ((uint64_t)(num).ldt.mantissah << BIN_DIGITS_IN_MANTISSAL)
+#define CONVERT_MANTISSA_TO_INTEGER(num, unbiased_exponent) ((long long int)((SHIFT_LEFT_MANTISSAH(num, unbiased_exponent) | (uint64_t)(num).ldt.mantissal) << ((unbiased_exponent) - BIN_DIGITS_IN_FRACTION)))
+#define ROUND_MANTISSA_TO_INTEGER(num, unbiased_exponent) \
+(__gnuc_extension__ \
+ ({ \
+ uint32_t rounded_mantissal = (uint32_t)(num).ldt.mantissal + (0x80000000UL >> ((unbiased_exponent) - BIN_DIGITS_IN_MANTISSAH)); \
+ if (result = (long long int)(num).ldt.mantissah, rounded_mantissal < (num).ldt.mantissal) \
+ result++; \
+ if ((unbiased_exponent) > BIN_DIGITS_IN_MANTISSAH) \
+ result = result << ((unbiased_exponent) - BIN_DIGITS_IN_MANTISSAH) | rounded_mantissal >> (BIN_DIGITS_IN_FRACTION - (unbiased_exponent)); \
+ (long long int)result; \
+ }) \
+)
+
+
+#ifdef __STDC__
+long long int
+llroundl(long double x)
+#else
+long long int
+llroundl(x)
+long double x;
+#endif
+{
+ _longdouble_union_t ieee_value;
+ int unbiased_exponent, sign;
+ long long int result;
+
+
+ ieee_value.ld = x;
+ unbiased_exponent = ieee_value.ldt.exponent - LONG_DOUBLE_BIAS;
+ sign = ieee_value.ldt.sign;
+
+ if (MAGNITUDE_IS_TOO_LARGE(unbiased_exponent)) /* The number is too large. */
+ return (long long int)x; /* It is left implementation defined what happens. */
+ else if (NO_SIGNIFICANT_DIGITS_IN_MANTISSAL(unbiased_exponent))
+ {
+ if (MAGNITUDE_IS_LESS_THAN_ONE(unbiased_exponent))
+ result = MAGNITUDE_IS_LESS_THAN_ONE_HALF(unbiased_exponent) ? 0 : 1;
+ else
+ result = ROUND_MANTISSAH_TO_INTEGER(ieee_value, unbiased_exponent);
+
+ return sign ? -result : result;
+ }
+ else
+ {
+ if (ALL_DIGITS_ARE_SIGNIFICANT(unbiased_exponent))
+ result = CONVERT_MANTISSA_TO_INTEGER(ieee_value, unbiased_exponent); /* >= 2^63 is already an exact integer. */
+ else
+ result = ROUND_MANTISSA_TO_INTEGER(ieee_value, unbiased_exponent);
+
+ return sign ? -result : result;
+ }
+}
diff -aprNU5 djgpp.orig/src/libm/math/lround.c djgpp/src/libm/math/lround.c
--- djgpp.orig/src/libm/math/lround.c 1970-01-01 01:00:00 +0100
+++ djgpp/src/libm/math/lround.c 2013-10-16 22:34:56 +0100
@@ -0,0 +1,112 @@
+/* Copyright (C) 2013 DJ Delorie, see COPYING.DJ for details */
+
+/*
+<<lround>>, <<lroundf>>, <<lroundl>>--round to integer, to nearest
+INDEX
+ lround
+INDEX
+ lroundf
+INDEX
+ lroundl
+
+ANSI_SYNOPSIS
+ #include <math.h>
+ long int lround(double <[x]>);
+ long int lroundf(float <[x]>);
+ long int lroundl(long double <[x]>);
+
+DESCRIPTION
+ The <<lround>>, <<lroundl>> and <<lroundl>> functions round their
+ argument to the nearest integer value, rounding halfway cases away from
+ zero, regardless of the current rounding direction. If the rounded
+ value is outside the range of the return type, the numeric result is
+ unspecified (depending upon the floating-point implementation, not the
+ library). A range error may occur if the magnitude of x is too large.
+
+RETURNS
+ <[x]> rounded to an integral value as an integer.
+
+SEEALSO
+ See the <<round>> functions for the return being the same floating-point
+ type as the argument. See also <<lrint>>.
+
+PORTABILITY
+ANSI C, POSIX
+
+*/
+
+#include <stdint.h>
+#include <math.h>
+#include <libc/ieee.h>
+
+#if defined (__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8))
+# define __gnuc_extension__ __extension__
+#else
+# define __gnuc_extension__
+#endif
+
+#define DOUBLE_BIAS (0x3FFU)
+#define BIN_DIGITS_IN_FRACTION (52) /* Amount of binary digits in fraction part of mantissa. */
+#define BIN_DIGITS_IN_MANTISSAH (20) /* Amount of binary digits in msw of the fraction part of mantissa. */
+#define ALL_DIGITS_ARE_SIGNIFICANT(exp) ((exp) > (BIN_DIGITS_IN_FRACTION - 1))
+#define NO_SIGNIFICANT_DIGITS_IN_MANTISSAL(exp) ((exp) < BIN_DIGITS_IN_MANTISSAH)
+#define MAGNITUDE_IS_TOO_LARGE(exp) ((exp) > (int)(sizeof(long int) * 8) - 2)
+#define MAGNITUDE_IS_LESS_THAN_ONE(exp) ((exp) < 0)
+#define MAGNITUDE_IS_LESS_THAN_ONE_HALF(exp) ((exp) < -1)
+
+#define ROUND_MANTISSAH_TO_INTEGER(num, unbiased_exponent) ((long int)((((uint32_t)(num).dt.mantissah | 0x00100000UL) + (0x0080000UL >> (unbiased_exponent))) >> (BIN_DIGITS_IN_MANTISSAH - (unbiased_exponent))))
+
+#define SHIFT_LEFT_MANTISSAH(num, unbiased_exponent) (((uint64_t)(num).dt.mantissah | 0x00100000ULL) << ((unbiased_exponent) - BIN_DIGITS_IN_MANTISSAH))
+#define SHIFT_LEFT_MANTISSAL(num, unbiased_exponent) ((uint64_t)(num).dt.mantissal << ((unbiased_exponent) - BIN_DIGITS_IN_FRACTION))
+#define CONVERT_MANTISSA_TO_INTEGER(num, unbiased_exponent) ((long int)(SHIFT_LEFT_MANTISSAH(num, unbiased_exponent) | SHIFT_LEFT_MANTISSAL(num, unbiased_exponent)))
+#define ROUND_MANTISSA_TO_INTEGER(num, unbiased_exponent) \
+(__gnuc_extension__ \
+ ({ \
+ uint32_t rounded_mantissal = (uint32_t)(num).dt.mantissal + (0x80000000UL >> ((unbiased_exponent) - BIN_DIGITS_IN_MANTISSAH)); \
+ if (result = ((long int)(num).dt.mantissah | 0x00100000UL), rounded_mantissal < (num).dt.mantissal) result++; \
+ if ((unbiased_exponent) > BIN_DIGITS_IN_MANTISSAH) \
+ result = result << ((unbiased_exponent) - BIN_DIGITS_IN_MANTISSAH) | rounded_mantissal >> (BIN_DIGITS_IN_FRACTION - (unbiased_exponent)); \
+ (long int)result; \
+ }) \
+)
+
+
+#ifdef __STDC__
+long int
+lround(double x)
+#else
+long int
+lround(x)
+double x;
+#endif
+{
+ _double_union_t ieee_value;
+ int unbiased_exponent, sign;
+ long int result;
+
+
+ ieee_value.d = x;
+ unbiased_exponent = ieee_value.dt.exponent - DOUBLE_BIAS;
+ sign = ieee_value.dt.sign;
+
+ if (MAGNITUDE_IS_TOO_LARGE(unbiased_exponent)) /* The number is too large. */
+ return (long int)x; /* It is left implementation defined what happens. */
+ else if (NO_SIGNIFICANT_DIGITS_IN_MANTISSAL(unbiased_exponent))
+ {
+ if (MAGNITUDE_IS_LESS_THAN_ONE(unbiased_exponent))
+ result = MAGNITUDE_IS_LESS_THAN_ONE_HALF(unbiased_exponent) ? 0 : 1;
+ else
+ result = ROUND_MANTISSAH_TO_INTEGER(ieee_value, unbiased_exponent);
+
+ return sign ? -result : result;
+ }
+ else
+ {
+ if (ALL_DIGITS_ARE_SIGNIFICANT(unbiased_exponent)) /* >= 2^52 is already an exact integer iff long int is 64 bit. */
+ result = CONVERT_MANTISSA_TO_INTEGER(ieee_value, unbiased_exponent); /* But this is not the case with djgpp. */
+ else
+ result = ROUND_MANTISSA_TO_INTEGER(ieee_value, unbiased_exponent);
+
+ return sign ? -result : result;
+ }
+}
diff -aprNU5 djgpp.orig/src/libm/math/lroundf.c djgpp/src/libm/math/lroundf.c
--- djgpp.orig/src/libm/math/lroundf.c 1970-01-01 01:00:00 +0100
+++ djgpp/src/libm/math/lroundf.c 2013-10-16 22:34:54 +0100
@@ -0,0 +1,47 @@
+/* Copyright (C) 2013 DJ Delorie, see COPYING.DJ for details */
+
+#include <stdint.h>
+#include <math.h>
+#include <libc/ieee.h>
+
+#define FLOAT_BIAS (0x7FU)
+#define BIN_DIGITS_IN_FRACTION (23) /* Amount of binary digits in fraction part of mantissa. */
+#define MAGNITUDE_IS_TOO_LARGE(exp) ((exp) > (int)(sizeof(long int) * 8) - 2)
+#define MAGNITUDE_IS_LESS_THAN_ONE(exp) ((exp) < 0)
+#define MAGNITUDE_IS_LESS_THAN_ONE_HALF(exp) ((exp) < -1)
+#define CONVERT_MANTISSA_TO_INTEGER(num, unbiased_exponent) ((long int)((uint32_t)(num).ft.mantissa | 0x00800000UL) << ((unbiased_exponent) - BIN_DIGITS_IN_FRACTION))
+#define ROUND_MANTISSA_TO_INTEGER(num, unbiased_exponent) ((long int)((((uint32_t)(num).ft.mantissa | 0x00800000UL) + (0x00400000UL >> (unbiased_exponent))) >> (BIN_DIGITS_IN_FRACTION - (unbiased_exponent))))
+
+
+#ifdef __STDC__
+long int
+lroundf(float x)
+#else
+long int
+lroundf(x)
+float x;
+#endif
+{
+ _float_union_t ieee_value;
+ int unbiased_exponent, sign;
+ long int result;
+
+
+ ieee_value.f = x;
+ unbiased_exponent = ieee_value.ft.exponent - FLOAT_BIAS;
+ sign = ieee_value.ft.sign;
+
+ if (MAGNITUDE_IS_TOO_LARGE(unbiased_exponent)) /* The number is too large. */
+ return (long int)x; /* It is left implementation defined what happens. */
+ else
+ {
+ if (MAGNITUDE_IS_LESS_THAN_ONE(unbiased_exponent))
+ result = MAGNITUDE_IS_LESS_THAN_ONE_HALF(unbiased_exponent) ? 0 : 1;
+ else if (unbiased_exponent > (BIN_DIGITS_IN_FRACTION - 1))
+ result = CONVERT_MANTISSA_TO_INTEGER(ieee_value, unbiased_exponent); /* >= 2^23 is already an exact integer. */
+ else
+ result = ROUND_MANTISSA_TO_INTEGER(ieee_value, unbiased_exponent);
+
+ return sign ? -result : result;
+ }
+}
diff -aprNU5 djgpp.orig/src/libm/math/lroundl.c djgpp/src/libm/math/lroundl.c
--- djgpp.orig/src/libm/math/lroundl.c 1970-01-01 01:00:00 +0100
+++ djgpp/src/libm/math/lroundl.c 2013-10-19 10:19:16 +0100
@@ -0,0 +1,94 @@
+/* Copyright (C) 2013 DJ Delorie, see COPYING.DJ for details */
+
+#include <stdint.h>
+#include <math.h>
+#include <libc/ieee.h>
+
+#if defined (__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8))
+# define __gnuc_extension__ __extension__
+#else
+# define __gnuc_extension__
+#endif
+
+#define LONG_DOUBLE_BIAS (0x3FFFU)
+#define BIN_DIGITS_IN_FRACTION (63) /* Amount of binary digits in fraction part of mantissa. */
+#define BIN_DIGITS_IN_MANTISSAH (31) /* Amount of binary digits in msw of the fraction part of mantissa. */
+#define ALL_DIGITS_ARE_SIGNIFICANT(exp) ((exp) > (BIN_DIGITS_IN_FRACTION - 1))
+#define NO_SIGNIFICANT_DIGITS_IN_MANTISSAL(exp) ((exp) < BIN_DIGITS_IN_MANTISSAH)
+#define MAGNITUDE_IS_TOO_LARGE(exp) ((exp) > (int)(sizeof(long int) * 8) - 2)
+#define MAGNITUDE_IS_LESS_THAN_ONE(exp) ((exp) < 0)
+#define MAGNITUDE_IS_LESS_THAN_ONE_HALF(exp) ((exp) < -1)
+
+#define CARRY_INTO_INTEGER_PART(x) ((x) & 0x100000000ULL)
+#define ROUND_MANTISSAH_TO_INTEGER(num, unbiased_exponent) \
+(__gnuc_extension__ \
+ ({ \
+ uint64_t rounded_mantissah = (uint64_t)(num).ldt.mantissah + (0x40000000ULL >> (unbiased_exponent)); \
+ if (CARRY_INTO_INTEGER_PART(rounded_mantissah)) \
+ { \
+ rounded_mantissah >>= 1; \
+ (unbiased_exponent)++; \
+ } \
+ (long int)(rounded_mantissah >> (BIN_DIGITS_IN_MANTISSAH - (unbiased_exponent))); \
+ }) \
+)
+
+#define SHIFT_LEFT_MANTISSAH(num, unbiased_exponent) ((uint64_t)(num).ldt.mantissah << ((unbiased_exponent) - BIN_DIGITS_IN_MANTISSAH))
+#define SHIFT_LEFT_MANTISSAL(num, unbiased_exponent) ((uint64_t)(num).ldt.mantissal << ((unbiased_exponent) - BIN_DIGITS_IN_FRACTION))
+#define CONVERT_MANTISSA_TO_INTEGER(num, unbiased_exponent) ((long int)(SHIFT_LEFT_MANTISSAH(num, unbiased_exponent) | SHIFT_LEFT_MANTISSAL(num, unbiased_exponent)))
+#define ROUND_MANTISSA_TO_INTEGER(num, unbiased_exponent) \
+(__gnuc_extension__ \
+ ({ \
+ uint32_t rounded_mantissal = (uint32_t)(num).ldt.mantissal + (0x80000000UL >> ((unbiased_exponent) - BIN_DIGITS_IN_MANTISSAH)); \
+ if (result = (long int)(num).ldt.mantissah, rounded_mantissal < (num).ldt.mantissal) \
+ { \
+ uint64_t rounded_mantissah = (uint64_t)result + 1; \
+ if (CARRY_INTO_INTEGER_PART(rounded_mantissah)) \
+ result = (long int)(rounded_mantissah >> 1); \
+ } \
+ if ((unbiased_exponent) > BIN_DIGITS_IN_MANTISSAH) \
+ result = result << ((unbiased_exponent) - BIN_DIGITS_IN_MANTISSAH) | rounded_mantissal >> (BIN_DIGITS_IN_FRACTION - (unbiased_exponent)); \
+ (long int)result; \
+ }) \
+)
+
+
+#ifdef __STDC__
+long int
+lroundl(long double x)
+#else
+long int
+lroundl(x)
+long double x;
+#endif
+{
+ _longdouble_union_t ieee_value;
+ int unbiased_exponent, sign;
+ long int result;
+
+
+ ieee_value.ld = x;
+ unbiased_exponent = ieee_value.ldt.exponent - LONG_DOUBLE_BIAS;
+ sign = ieee_value.ldt.sign;
+
+ if (MAGNITUDE_IS_TOO_LARGE(unbiased_exponent)) /* The number is too large. */
+ return (long int)x; /* It is left implementation defined what happens. */
+ else if (NO_SIGNIFICANT_DIGITS_IN_MANTISSAL(unbiased_exponent))
+ {
+ if (MAGNITUDE_IS_LESS_THAN_ONE(unbiased_exponent))
+ result = MAGNITUDE_IS_LESS_THAN_ONE_HALF(unbiased_exponent) ? 0 : 1;
+ else
+ result = ROUND_MANTISSAH_TO_INTEGER(ieee_value, unbiased_exponent);
+
+ return sign ? -result : result;
+ }
+ else
+ {
+ if (ALL_DIGITS_ARE_SIGNIFICANT(unbiased_exponent)) /* >= 2^63 is already an exact integer iff long int is 64 bit. */
+ result = CONVERT_MANTISSA_TO_INTEGER(ieee_value, unbiased_exponent); /* But this is not the case with djgpp. */
+ else
+ result = ROUND_MANTISSA_TO_INTEGER(ieee_value, unbiased_exponent);
+
+ return sign ? -result : result;
+ }
+}
diff -aprNU5 djgpp.orig/src/libm/math/makefile djgpp/src/libm/math/makefile
--- djgpp.orig/src/libm/math/makefile 2013-10-14 22:37:58 +0100
+++ djgpp/src/libm/math/makefile 2013-10-17 20:37:26 +0100
@@ -174,10 +174,16 @@ SRC += llrint.c
SRC += llrintf.c
SRC += llrintl.c
SRC += round.c
SRC += roundf.c
SRC += roundl.c
+SRC += lround.c
+SRC += lroundf.c
+SRC += lroundl.c
+SRC += llround.c
+SRC += llroundf.c
+SRC += llroundl.c
chobj = w_acos.def w_acosh.def w_asin.def s_asinh.def \
s_atan.def w_atan2.def w_atanh.def w_j0.def \
s_copysign.def w_cosh.def s_erf.def w_exp.def \
s_fabs.def s_floor.def w_fmod.def s_frexp.def \
@@ -185,11 +191,11 @@ chobj = w_acos.def w_acosh.def w_asin.de
w_log10.def s_log1p.def s_matherr.def s_modf.def \
w_pow.def w_remainder.def s_sin.def w_sinh.def \
s_cbrt.def w_sqrt.def s_tan.def s_tanh.def \
s_infinity.def s_isnan.def s_scalbn.def s_nextafter.def \
s_nan.def s_ilogb.def s_expm1.def trunc.def \
- lrint.def llrint.def round.def
+ lrint.def llrint.def round.def lround.def llround.def
CFLAGS = -D_USE_LIBM_MATH_H
EXTRA_FILES = $(TOP)/../../info/libm.info
# chew emits non-fatal warnings, so we redirect them to the void
CHEW = ./chew.exe -f ./doc.str -e /dev/null
diff -aprNU5 djgpp.orig/tests/cygnus/makefile djgpp/tests/cygnus/makefile
--- djgpp.orig/tests/cygnus/makefile 2013-10-14 22:37:58 +0100
+++ djgpp/tests/cygnus/makefile 2013-10-14 22:40:02 +0100
@@ -93,11 +93,11 @@ VEC_OFILES = $(GEN_VEC_FILES:.c=.o)
$(OFILES): CFLAGS = $(DEFS) -fno-builtin -O2 -g -Wall
all: check
check: mtest.exe t-trunc.exe t-truncf.exe t-truncl.exe t-lrint.exe t-lrintf.exe t-lrintl.exe t-llrint.exe t-llrintl.exe \
- t-roundf.exe t-round.exe t-roundl.exe
+ t-roundf.exe t-round.exe t-roundl.exe t-lround.exe t-lroundf.exe t-lroundl.exe t-llround.exe t-llroundf.exe t-llroundl.exe
./mtest.exe > mtest.results
./t-trunc.exe > ttest.results
./t-truncf.exe >> ttest.results
./t-truncl.exe >> ttest.results
./t-lrintf.exe >> ttest.results
@@ -106,10 +106,16 @@ check: mtest.exe t-trunc.exe t-truncf.ex
./t-llrint.exe >> ttest.results
./t-llrintl.exe >> ttest.results
./t-roundf.exe >> ttest.results
./t-round.exe >> ttest.results
./t-roundl.exe >> ttest.results
+ ./t-lroundf.exe >> ttest.results
+ ./t-lround.exe >> ttest.results
+ ./t-lroundl.exe >> ttest.results
+ ./t-llroundf.exe >> ttest.results
+ ./t-llround.exe >> ttest.results
+ ./t-llroundl.exe >> ttest.results
# Pattern rules to generate test vectors. (The funky vec.c=%.c replacement
# is meant to create a pattern rule where actually a normal rule will
# do, since only pattern rules can tell Make that several targets are
# generated all at once. Without this, Make will invoke the vector-
@@ -168,13 +174,31 @@ t-round.exe: t-round.o
$(CC) -o $@ $(LDFLAGS) t-round.o $(LIBS)
t-roundl.exe: t-roundl.o
$(CC) -o $@ $(LDFLAGS) t-roundl.o $(LIBS)
+t-lroundf.exe: t-lroundf.o
+ $(CC) -o $@ $(LDFLAGS) t-lroundf.o $(LIBS)
+
+t-lround.exe: t-lround.o
+ $(CC) -o $@ $(LDFLAGS) t-lround.o $(LIBS)
+
+t-lroundl.exe: t-lroundl.o
+ $(CC) -o $@ $(LDFLAGS) t-lroundl.o $(LIBS)
+
+t-llroundf.exe: t-llroundf.o
+ $(CC) -o $@ $(LDFLAGS) t-llroundf.o $(LIBS)
+
+t-llround.exe: t-llround.o
+ $(CC) -o $@ $(LDFLAGS) t-llround.o $(LIBS)
+
+t-llroundl.exe: t-llroundl.o
+ $(CC) -o $@ $(LDFLAGS) t-llroundl.o $(LIBS)
+
$(OFILES) $(VEC_OFILES) : test.h
clean mostlyclean:
-cd tgen; $(MAKE) $@
- cd $(HERE); $(RM) $(OFILES) $(VEC_OFILES) *~ *.exe mtest.results ttest.results t-trunc*.o t-lrint*.o t-llrint*.o t-round*.o
+ cd $(HERE); $(RM) $(OFILES) $(VEC_OFILES) *~ *.exe mtest.results ttest.results t-trunc*.o t-lrint*.o t-llrint*.o t-round*.o t-lround*.o t-llround*.o
.SECONDARY: $(GEN_PROGS) $(GEN_VEC_FILES)
.PHONY: all check clean mostlyclean
diff -aprNU5 djgpp.orig/tests/cygnus/t-llround.c djgpp/tests/cygnus/t-llround.c
--- djgpp.orig/tests/cygnus/t-llround.c 1970-01-01 01:00:00 +0100
+++ djgpp/tests/cygnus/t-llround.c 2013-10-16 22:20:50 +0100
@@ -0,0 +1,198 @@
+/* Copyright (C) 2013 DJ Delorie, see COPYING.DJ for details */
+
+
+#include <stdio.h>
+#include <math.h>
+#include <libc/ieee.h>
+
+typedef struct {
+ const _double_union_t value; /* test value */
+ const long long int should_be; /* result */
+} entry_t;
+
+static const entry_t tests_double[] =
+{
+ /* test value */
+ /* value should be */
+
+ /* Zeros. */
+ {{.dt = {0x0U, 0x0U, 0x0U, 0}}, 0}, /* 0.0 */
+ {{.dt = {0x0U, 0x0U, 0x0U, 1}}, 0}, /* -0.0 */
+
+ /* Subnormals aka denormals. */
+ {{.dt = {0x1U, 0x0U, 0x0U, 0}}, 0}, /* Very small number. */
+ {{.dt = {0x1U, 0x0U, 0x0U, 1}}, 0}, /* Very small -number. */
+
+ /* Normals. */
+ {{.dt = {0x1U, 0x0U, 0x1U, 0}}, 0}, /* Small number. */
+ {{.dt = {0x1U, 0x0U, 0x1U, 1}}, 0}, /* Small -number. */
+ {{.dt = {0xFFFFFFFFU, 0x7FFFFU, 0x7FEU, 0}}, -9.223372036854775808E18}, /* Big number. */
+ {{.dt = {0xFFFFFFFFU, 0x7FFFFU, 0x7FEU, 1}}, -9.223372036854775808E18}, /* Big -number. */
+
+ /* Infs. */
+ {{.dt = {0x0U, 0x0U, 0x7FFU, 0}}, -9.223372036854775808E18}, /* Inf */
+ {{.dt = {0x0U, 0x0U, 0x7FFU, 1}}, -9.223372036854775808E18}, /* -Inf */
+
+ /* NaNs. */
+ {{.dt = {0x1U, 0x0U, 0x7FFU, 0}}, -9.223372036854775808E18}, /* SNaN */
+ {{.dt = {0x1U, 0x0U, 0x7FFU, 1}}, -9.223372036854775808E18}, /* -SNaN */
+ {{.dt = {0x0U, 0xFFFFFU, 0x7FFU, 1}}, -9.223372036854775808E18}, /* QNaN */
+ {{.dt = {0x0U, 0xFFFFFU, 0x7FFU, 0}}, -9.223372036854775808E18}, /* -QNaN */
+
+
+ /* Number. */
+ {{.dt = {0x54442D18U, 0x921FBU, 0x3FFU + 0x001U, 0}}, +3}, /* PI */
+ {{.dt = {0x54442D18U, 0x921FBU, 0x3FFU + 0x001U, 1}}, -3}, /* -PI */
+
+ {{.dt = {0x00000000U, 0xE0000U, 0x3FFU + 0x0U, 0}}, +2}, /* 1.875000 */
+ {{.dt = {0x00000000U, 0xE0000U, 0x3FFU + 0x0U, 1}}, -2}, /* -1.875000 */
+ {{.dt = {0x00000000U, 0xA0000U, 0x3FFU + 0x0U, 0}}, +2}, /* 1.625000 */
+ {{.dt = {0x00000000U, 0xA0000U, 0x3FFU + 0x0U, 1}}, -2}, /* -1.625000 */
+ {{.dt = {0x18DEF417U, 0x80002U, 0x3FFU + 0x0U, 0}}, +2}, /* 1.500002 */
+ {{.dt = {0x18DEF417U, 0x80002U, 0x3FFU + 0x0U, 1}}, -2}, /* -1.500002 */
+ {{.dt = {0x00000000U, 0x80000U, 0x3FFU + 0x0U, 0}}, +2}, /* 1.500000 */
+ {{.dt = {0x00000000U, 0x80000U, 0x3FFU + 0x0U, 1}}, -2}, /* -1.500000 */
+ {{.dt = {0xE7210BE9U, 0x7F9FDU, 0x3FFU + 0x0U, 0}}, +1}, /* 1.499998 */
+ {{.dt = {0xE7210BE9U, 0x7F9FDU, 0x3FFU + 0x0U, 1}}, -1}, /* -1.499998 */
+ {{.dt = {0x00000000U, 0x60000U, 0x3FFU + 0x0U, 0}}, +1}, /* 1.375000 */
+ {{.dt = {0x00000000U, 0x60000U, 0x3FFU + 0x0U, 1}}, -1}, /* -1.375000 */
+ {{.dt = {0x00000000U, 0x20000U, 0x3FFU + 0x0U, 0}}, +1}, /* 1.125000 */
+ {{.dt = {0x00000000U, 0x20000U, 0x3FFU + 0x0U, 1}}, -1}, /* -1.125000 */
+
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0x016U, 0}}, +4194304}, /* 4194304.000000 */
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0x016U, 1}}, -4194304}, /* -4194304.000000 */
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0x017U, 0}}, +8388608}, /* 8388608.000000 */
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0x017U, 1}}, -8388608}, /* -8388608.000000 */
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0x018U, 0}}, +16777216}, /* 16777216.000000 */
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0x018U, 1}}, -16777216}, /* -16777216.000000 */
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0x01EU, 0}}, +1073741824}, /* 1073741824.000000 */
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0x01EU, 1}}, -1073741824}, /* -1073741824.000000 */
+ {{.dt = {0xFFC00000U, 0xFFFFFU, 0x3FFU + 0x01EU, 0}}, +2147483647LL}, /* 2147483647.000000 */
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0x01FU, 1}}, -2147483648LL}, /* -2147483648.000000 */
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0x020U, 0}}, +4294967296}, /* 4294967296.000000 */
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0x020U, 1}}, -4294967296}, /* -4294967296.000000 */
+ {{.dt = {0xACF13400U, 0x02468U, 0x3FFU + 0x033U, 0}}, 2271815812028928}, /* 2271815812028928.000000 */
+ {{.dt = {0xACF13400U, 0x02468U, 0x3FFU + 0x033U, 1}}, -2271815812028928}, /* -2271815812028928.000000 */
+
+ {{.dt = {0x56789AB0U, 0x01234U, 0x3FFU + 0x034U, 0}}, 4523615625714352}, /* 4523615625714352.000000 */
+ {{.dt = {0x56789AB0U, 0x01234U, 0x3FFU + 0x034U, 1}}, -4523615625714352}, /* -4523615625714352.000000 */
+ {{.dt = {0xA9876543U, 0xFEDCBU, 0x3FFU + 0x034U, 0}}, 8987183256397123}, /* 8987183256397123.000000 */
+ {{.dt = {0xA9876543U, 0xFEDCBU, 0x3FFU + 0x034U, 1}}, -8987183256397123}, /* -8987183256397123.000000 */
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0x035U, 0}}, 9007199254740992}, /* 9007199254740992.000000 */
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0x035U, 1}}, -9007199254740992}, /* -9007199254740992.000000 */
+ {{.dt = {0x6789ABCEU, 0x12345U, 0x3FFU + 0x035U, 0}}, 9647711201744796}, /* 9647711201744796.000000 */
+ {{.dt = {0x6789ABCEU, 0x12345U, 0x3FFU + 0x035U, 1}}, -9647711201744796}, /* -9647711201744796.000000 */
+
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0x03FU, 0}}, 9223372036854775808ULL}, /* 9223372036854775808.0000000000 */
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0x03FU, 1}}, -9.223372036854775808E+18}, /* -9223372036854775808.0000000000 */
+
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0x03EU, 0}}, 4611686018427387904}, /* 4611686018427387904.0000000000 */
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0x03EU, 1}}, -4611686018427387904}, /* -4611686018427387904.0000000000 */
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0x034U, 0}}, 4503599627370496}, /* 4503599627370496.0000000000 */
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0x034U, 1}}, -4503599627370496}, /* -4503599627370496.0000000000 */
+
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0x033U, 0}}, 2251799813685248}, /* 2251799813685248.0000000000 */
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0x033U, 1}}, -2251799813685248}, /* -2251799813685248.0000000000 */
+ {{.dt = {0x00000001U, 0x00000U, 0x3FFU + 0x033U, 0}}, 2251799813685249}, /* 2251799813685248.5000000000 */
+ {{.dt = {0x00000001U, 0x00000U, 0x3FFU + 0x033U, 1}}, -2251799813685249}, /* -2251799813685248.5000000000 */
+ {{.dt = {0x00000002U, 0x00000U, 0x3FFU + 0x033U, 0}}, 2251799813685249}, /* 2251799813685249.7500000000 */
+ {{.dt = {0x00000002U, 0x00000U, 0x3FFU + 0x033U, 1}}, -2251799813685249}, /* -2251799813685249.7500000000 */
+
+ {{.dt = {0x00000000U, 0xC0000U, 0x3FFU + 0x000U, 0}}, 2}, /* 1.7500000000 */
+ {{.dt = {0x00000000U, 0xC0000U, 0x3FFU + 0x000U, 1}}, -2}, /* -1.7500000000 */
+ {{.dt = {0x00000000U, 0x80000U, 0x3FFU + 0x000U, 0}}, 2}, /* 1.5000000000 */
+ {{.dt = {0x00000000U, 0x80000U, 0x3FFU + 0x000U, 1}}, -2}, /* -1.5000000000 */
+ {{.dt = {0x00000000U, 0x40000U, 0x3FFU + 0x000U, 0}}, 1}, /* 1.2500000000 */
+ {{.dt = {0x00000000U, 0x40000U, 0x3FFU + 0x000U, 1}}, -1}, /* -1.2500000000 */
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0x000U, 0}}, 1}, /* 1.0000000000 */
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0x000U, 1}}, -1}, /* -1.0000000000 */
+ {{.dt = {0x00000000U, 0x80000U, 0x3FFU + 0xFFFFFFFFU, 0}}, 1}, /* 0.7500000000 */
+ {{.dt = {0x00000000U, 0x80000U, 0x3FFU + 0xFFFFFFFFU, 1}}, -1}, /* -0.7500000000 */
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0xFFFFFFFFU, 0}}, 1}, /* 0.5000000000 */
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0xFFFFFFFFU, 1}}, -1}, /* -0.5000000000 */
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0xFFFFFFFEU, 0}}, 0}, /* 0.2500000000 */
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0xFFFFFFFEU, 1}}, -0}, /* -0.2500000000 */
+ {{.dt = {0xF8FAB5E6U, 0x948B0U, 0x3FFU + 0xFFFFFFF9U, 0}}, 0}, /* 0.0123456789 */
+ {{.dt = {0xF8FAB5E6U, 0x948B0U, 0x3FFU + 0xFFFFFFF9U, 1}}, -0}, /* -0.0123456789 */
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0xFFFFFC01U, 0}}, 0}, /* 0.0000000000 */
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0xFFFFFC01U, 1}}, -0}, /* -0.0000000000 */
+
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0x014U, 0}}, 1048576}, /* 1048576.0000000000 */
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0x014U, 1}}, -1048576}, /* -1048576.0000000000 */
+ {{.dt = {0x40000000U, 0x00000U, 0x3FFU + 0x014U, 0}}, 1048576}, /* 1048576.2500000000 */
+ {{.dt = {0x40000000U, 0x00000U, 0x3FFU + 0x014U, 1}}, -1048576}, /* -1048576.2500000000 */
+ {{.dt = {0x80000000U, 0x00000U, 0x3FFU + 0x014U, 0}}, 1048577}, /* 1048576.5000000000 */
+ {{.dt = {0x80000000U, 0x00000U, 0x3FFU + 0x014U, 1}}, -1048577}, /* -1048576.5000000000 */
+ {{.dt = {0xC0000000U, 0x00000U, 0x3FFU + 0x014U, 0}}, 1048577}, /* 1048576.7500000000 */
+ {{.dt = {0xC0000000U, 0x00000U, 0x3FFU + 0x014U, 1}}, -1048577}, /* -1048576.7500000000 */
+
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0x015U, 0}}, 2097152}, /* 2097152.0000000000 */
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0x015U, 1}}, -2097152}, /* -2097152.0000000000 */
+ {{.dt = {0x20000000U, 0x00000U, 0x3FFU + 0x015U, 0}}, 2097152}, /* 2097152.2500000000 */
+ {{.dt = {0x20000000U, 0x00000U, 0x3FFU + 0x015U, 1}}, -2097152}, /* -2097152.2500000000 */
+ {{.dt = {0x40000000U, 0x00000U, 0x3FFU + 0x015U, 0}}, 2097153}, /* 2097152.5000000000 */
+ {{.dt = {0x40000000U, 0x00000U, 0x3FFU + 0x015U, 1}}, -2097153}, /* -2097152.5000000000 */
+ {{.dt = {0x60000000U, 0x00000U, 0x3FFU + 0x015U, 0}}, 2097153}, /* 2097152.7500000000 */
+ {{.dt = {0x60000000U, 0x00000U, 0x3FFU + 0x015U, 1}}, -2097153}, /* -2097152.7500000000 */
+
+ /* Number greater than 2**63 exceeds long int size and will be casted in an implementation defined manner. */
+ {{.dt = {0x00000001U, 0x00000U, 0x3FFU + 0x03FU, 0}}, -9.223372036854775808E+18}, /* 9223372036854777856.0000000000 */
+ {{.dt = {0x00000001U, 0x00000U, 0x3FFU + 0x03FU, 1}}, -9.223372036854775808E+18}, /* -9223372036854777856.0000000000 */
+
+ /* Number less than 0.5 will be truncated to 0. */
+ {{.dt = {0x1FF885F3U, 0xFF793U, 0x3FFU + 0xFFFFFFFEU, 0}}, 0}, /* 0.4994857609 */
+ {{.dt = {0x1FF885F3U, 0xFF793U, 0x3FFU + 0xFFFFFFFEU, 1}}, -0}, /* -0.4994857609 */
+ {{.dt = {0xD2F1A9FCU, 0x0624DU, 0x3FFU + 0xFFFFFFF6U, 0}}, 0}, /* 0.0010000000 */
+ {{.dt = {0xD2F1A9FCU, 0x0624DU, 0x3FFU + 0xFFFFFFF6U, 1}}, -0}, /* -0.0010000000 */
+
+ /* Number greater than 0.5 and less than 1 will be rounded to 1. */
+ {{.dt = {0x8FB86F48U, 0xF9ADCU, 0x3FFU + 0xFFFFFFFFU, 0}}, 1}, /* 0.9876540000 */
+ {{.dt = {0x8FB86F48U, 0xF9ADCU, 0x3FFU + 0xFFFFFFFFU, 1}}, -1}, /* -0.9876540000 */
+ {{.dt = {0x20365653U, 0x00000U, 0x3FFU + 0xFFFFFFFFU, 0}}, 1}, /* 0.5000000600 */
+ {{.dt = {0x20365653U, 0x00000U, 0x3FFU + 0xFFFFFFFFU, 1}}, -1}, /* -0.5000000600 */
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0xFFFFFFFFU, 0}}, 1}, /* 0.5000000000 */
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0xFFFFFFFFU, 1}}, -1}, /* -0.5000000000 */
+
+ /* Number greather than 1 and less than 2**63 will be rounded accordingly. */
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0x000U, 0}}, 1}, /* 1.0000000000 */
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0x000U, 1}}, -1}, /* -1.0000000000 */
+ {{.dt = {0x18DEF417U, 0x00002U, 0x3FFU + 0x000U, 0}}, 1}, /* 1.0000020000 */
+ {{.dt = {0x18DEF417U, 0x00002U, 0x3FFU + 0x000U, 1}}, -1}, /* -1.0000020000 */
+ {{.dt = {0x00000000U, 0x00003U, 0x3FFU + 0x010U, 0}}, 65536}, /* 65536.1875000000 */
+ {{.dt = {0x00000000U, 0x00003U, 0x3FFU + 0x010U, 1}}, -65536}, /* -65536.1875000000 */
+ {{.dt = {0x00000000U, 0x00008U, 0x3FFU + 0x010U, 0}}, 65537}, /* 65536.5000000000 */
+ {{.dt = {0x00000000U, 0x00008U, 0x3FFU + 0x010U, 1}}, -65537}, /* -65536.5000000000 */
+ {{.dt = {0xA0000000U, 0x00009U, 0x3FFU + 0x010U, 0}}, 65537}, /* 65536.6015625000 */
+ {{.dt = {0xA0000000U, 0x00009U, 0x3FFU + 0x010U, 1}}, -65537}, /* -65536.6015625000 */
+ {{.dt = {0xE0000000U, 0xFFFFFU, 0x3FFU + 0x016U, }}, 8388608}, /* 8388607.5000000000 */
+ {{.dt = {0xE0000000U, 0xFFFFFU, 0x3FFU + 0x016U, 1}}, -8388608}, /* -8388607.5000000000 */
+ {{.dt = {0xA0000000U, 0x00000U, 0x3FFU + 0x014U, 0}}, 1048577}, /* 1048576.6250000000 */
+ {{.dt = {0xA0000000U, 0x00000U, 0x3FFU + 0x014U, 1}}, -1048577}, /* -1048576.6250000000 */
+ {{.dt = {0xFFC00000U, 0xFFFFFU, 0x3FFU + 0x01EU, 0}}, 2147483647}, /* 2147483647.0000000000 */
+ {{.dt = {0xFFC00000U, 0xFFFFFU, 0x3FFU + 0x01EU, 1}}, -2147483647}, /* -2147483647.0000000000 */
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0x034U, 0}}, 4503599627370496}, /* 4503599627370496.0000000000 */
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0x034U, 1}}, -4503599627370496}, /* -4503599627370496.0000000000 */
+ {{.dt = {0xFFFFFFFEU, 0xFFFFFU, 0x3FFU + 0x03EU, 0}}, 9223372036854773760}, /* 9223372036854773760.0000000000 */
+ {{.dt = {0xFFFFFFFEU, 0xFFFFFU, 0x3FFU + 0x03EU, 1}}, -9223372036854773760}, /* -9223372036854773760.0000000000 */
+};
+
+static const size_t n_tests_double = sizeof(tests_double) / sizeof(tests_double[0]);
+
+
+int main(void)
+{
+ unsigned int i, counter;
+
+ for (counter = i = 0; i < n_tests_double; i++)
+ {
+ long long int result = llround(tests_double[i].value.d);
+
+ if (tests_double[i].should_be == result)
+ counter++;
+ else
+ printf("llround test failed: value to round = %.6g result = %lld should be = %lld\n", tests_double[i].value.d, result, tests_double[i].should_be);
+ }
+ printf("%s\n", (counter < n_tests_double) ? "llround test failed." : "llround test succeded.");
+
+ return 0;
+}
diff -aprNU5 djgpp.orig/tests/cygnus/t-llroundf.c djgpp/tests/cygnus/t-llroundf.c
--- djgpp.orig/tests/cygnus/t-llroundf.c 1970-01-01 01:00:00 +0100
+++ djgpp/tests/cygnus/t-llroundf.c 2013-10-14 22:40:02 +0100
@@ -0,0 +1,137 @@
+/* Copyright (C) 2013 DJ Delorie, see COPYING.DJ for details */
+
+
+#include <stdio.h>
+#include <math.h>
+#include <libc/ieee.h>
+
+typedef struct {
+ const _float_union_t value; /* test value */
+ const long long int should_be; /* result */
+} entry_t;
+
+static const entry_t tests_float[] =
+{
+ /* test value */
+ /* value should be */
+
+ /* Zeros. */
+ {{.ft = {0x0U, 0x0U, 0}}, 0}, /* 0.0 */
+ {{.ft = {0x0U, 0x0U, 1}}, 0}, /* -0.0 */
+
+ /* Subnormals aka denormals. */
+ {{.ft = {0x1U, 0x0U, 0}}, 0}, /* Very small number. */
+ {{.ft = {0x1U, 0x0U, 1}}, 0}, /* Very small -number. */
+
+ /* Normals. */
+ {{.ft = {0x1U, 0x1U, 0}}, 0}, /* Small number. */
+ {{.ft = {0x1U, 0x1U, 1}}, 0}, /* Small -number. */
+ {{.ft = {0xFFFFU, 0xFEU, 0}}, -9223372036854775808ULL}, /* Big number. */
+ {{.ft = {0xFFFFU, 0xFEU, 1}}, -9223372036854775808ULL}, /* Big -number. */
+
+ /* Infs. */
+ {{.ft = {0x0U, 0xFFU, 0}}, -9223372036854775808ULL}, /* Inf */
+ {{.ft = {0x0U, 0xFFU, 1}}, -9223372036854775808ULL}, /* -Inf */
+
+ /* NaNs. */
+ {{.ft = {0x1U, 0xFFU, 0}}, -9223372036854775808ULL}, /* SNaN */
+ {{.ft = {0x1U, 0xFFU, 1}}, -9223372036854775808ULL}, /* -SNaN */
+ {{.ft = {0x7FFFFFU, 0xFFU, 0}}, -9223372036854775808ULL}, /* QNaN */
+ {{.ft = {0x7FFFFFU, 0xFFU, 1}}, -9223372036854775808ULL}, /* -QNaN */
+
+ /* Numbers. */
+ {{.ft = {0x490FDBU, 0x80U, 0}}, +3}, /* PI */
+ {{.ft = {0x490FDBU, 0x80U, 1}}, -3}, /* -PI */
+
+ {{.ft = {0x700000U, 0x7FU, 0}}, +2}, /* 1.875000 */
+ {{.ft = {0x700000U, 0x7FU, 1}}, -2}, /* -1.875000 */
+ {{.ft = {0x500000U, 0x7FU, 0}}, +2}, /* 1.625000 */
+ {{.ft = {0x500000U, 0x7FU, 1}}, -2}, /* -1.625000 */
+ {{.ft = {0x40000FU, 0x7FU, 0}}, +2}, /* 1.500002 */
+ {{.ft = {0x40000FU, 0x7FU, 1}}, -2}, /* -1.500002 */
+ {{.ft = {0x400000U, 0x7FU, 0}}, +2}, /* 1.500000 */
+ {{.ft = {0x400000U, 0x7FU, 1}}, -2}, /* -1.500000 */
+ {{.ft = {0x3FFFF0U, 0x7FU, 0}}, +1}, /* 1.499998 */
+ {{.ft = {0x3FFFF0U, 0x7FU, 1}}, -1}, /* -1.499998 */
+ {{.ft = {0x300000U, 0x7FU, 0}}, +1}, /* 1.375000 */
+ {{.ft = {0x300000U, 0x7FU, 1}}, -1}, /* -1.375000 */
+ {{.ft = {0x100000U, 0x7FU, 0}}, +1}, /* 1.125000 */
+ {{.ft = {0x100000U, 0x7FU, 1}}, -1}, /* -1.125000 */
+
+ {{.ft = {0x000000U, 0x7FU + 0x16U, 0}}, +4194304}, /* 4194304.000000 */
+ {{.ft = {0x000000U, 0x7FU + 0x16U, 1}}, -4194304}, /* -4194304.000000 */
+ {{.ft = {0x000000U, 0x7FU + 0x17U, 0}}, +8388608}, /* 8388608.000000 */
+ {{.ft = {0x000000U, 0x7FU + 0x17U, 1}}, -8388608}, /* -8388608.000000 */
+ {{.ft = {0x000000U, 0x7FU + 0x18U, 0}}, +16777216}, /* 16777216.000000 */
+ {{.ft = {0x000000U, 0x7FU + 0x18U, 1}}, -16777216}, /* -16777216.000000 */
+
+ {{.ft = {0x000000U, 0x7FU + 0x1EU, 0}}, +1073741824}, /* 1073741824.000000 */
+ {{.ft = {0x000000U, 0x7FU + 0x1EU, 1}}, -1073741824}, /* -1073741824.000000 */
+ {{.ft = {0x000000U, 0x7FU + 0x1FU, 0}}, +2147483648LL}, /* 2147483648.000000 */
+ {{.ft = {0x000000U, 0x7FU + 0x1FU, 1}}, -2147483648LL}, /* -2147483648.000000 */
+ {{.ft = {0x000000U, 0x7FU + 0x20U, 0}}, 4294967296}, /* 4294967296.000000 */
+ {{.ft = {0x000000U, 0x7FU + 0x20U, 1}}, -4294967296}, /* -4294967296.000000 */
+
+ /* Different mantissa patterns. */
+ {{.ft = {0x7FFFFFU, 0x96U, 0}}, +16777215}, /* 16777215.000000 */
+ {{.ft = {0x7FF000U, 0x95U, 0}}, +8386560}, /* 8386560.000000 */
+ {{.ft = {0x1555FFU, 0x8DU, 0}}, +19115}, /* 19115.000000 */
+ {{.ft = {0x7FF000U, 0x96U, 1}}, -16773120}, /* -16773120.000000 */
+ {{.ft = {0x7FFFFEU, 0x95U, 1}}, -8388607}, /* -8388607.000000 */
+ {{.ft = {0x1555FFU, 0x8DU, 1}}, -19115}, /* -19115.000000 */
+
+ /* Number greater than 2**63 exceeds long long int size and will be casted in an implementation defined manner. */
+ {{.ft = {0x000001U, 0x7FU + 0x3FU, 0}}, +9223372036854775808ULL}, /* 9223372036854775808.000000 */
+ {{.ft = {0x000001U, 0x7FU + 0x3FU, 1}}, -9223372036854775808ULL}, /* -9223372036854775808.000000 */
+
+ /* Number less than 0.5 will be truncated to 0. */
+ {{.ft = {0x7FBC99U, 0x7FU + 0xFFFFFFFEU, 0}}, 0}, /* 0.4994857609 */
+ {{.ft = {0x7FBC99U, 0x7FU + 0xFFFFFFFEU, 1}}, -0}, /* -0.4994857609 */
+ {{.ft = {0x03126FU, 0x7FU + 0xFFFFFFF6U, 0}}, 0}, /* 0.001000 */
+ {{.ft = {0x03126FU, 0x7FU + 0xFFFFFFF6U, 1}}, -0}, /* -0.001000 */
+
+ /* Number greater than 0.5 and less than 1 will be rounded to 1. */
+ {{.ft = {0x7CD6EAU, 0x7FU + 0xFFFFFFFFU, 0}}, 1}, /* 0.987654 */
+ {{.ft = {0x7CD6EAU, 0x7FU + 0xFFFFFFFFU, 1}}, -1}, /* -0.987654 */
+ {{.ft = {0x000001U, 0x7FU + 0xFFFFFFFFU, 0}}, 1}, /* 0.50000006 */
+ {{.ft = {0x000001U, 0x7FU + 0xFFFFFFFFU, 1}}, -1}, /* -0.50000006 */
+ {{.ft = {0x000000U, 0x7FU + 0xFFFFFFFFU, 0}}, 1}, /* 0.500000 */
+ {{.ft = {0x000000U, 0x7FU + 0xFFFFFFFFU, 1}}, -1}, /* -0.500000 */
+
+ /* Number greather than 1 and less than 2**23 will be rounded accordingly. */
+ {{.ft = {0x000000U, 0x7FU + 0x00U, 0}}, 1}, /* 1.0000000000 */
+ {{.ft = {0x000000U, 0x7FU + 0x00U, 1}}, -1}, /* 1.0000000000 */
+ {{.ft = {0x00000FU, 0x7FU + 0x00U, 0}}, 1}, /* 1.000002 */
+ {{.ft = {0x00000FU, 0x7FU + 0x00U, 1}}, -1}, /* 1.000002 */
+ {{.ft = {0x000018U, 0x7FU + 0x10U, 0}}, 65536}, /* 65536.1875000000 */
+ {{.ft = {0x000018U, 0x7FU + 0x10U, 1}}, -65536}, /* -65536.1875000000 */
+ {{.ft = {0x000040U, 0x7FU + 0x10U, 0}}, 65537}, /* 65536.5000000 */
+ {{.ft = {0x000040U, 0x7FU + 0x10U, 1}}, -65537}, /* -65536.5000000 */
+ {{.ft = {0x00004DU, 0x7FU + 0x10U, 0}}, 65537}, /* 65536.6015625000 */
+ {{.ft = {0x00004DU, 0x7FU + 0x10U, 1}}, -65537}, /* -65536.6015625000 */
+ {{.ft = {0x7FFFFFU, 0x7FU + 0x16U, 0}}, 8388608}, /* 8388607.5000000000 */
+ {{.ft = {0x7FFFFFU, 0x7FU + 0x16U, 1}}, -8388608}, /* -8388607.5000000000 */
+ {{.ft = {0x000005U, 0x7FU + 0x14U, 0}}, 1048577}, /* 1048576.6250000000 */
+ {{.ft = {0x000005U, 0x7FU + 0x14U, 1}}, -1048577}, /* -1048576.6250000000 */
+};
+
+static const size_t n_tests_float = sizeof(tests_float) / sizeof(tests_float[0]);
+
+
+int main(void)
+{
+ unsigned int i, counter;
+
+ for (counter = i = 0; i < n_tests_float; i++)
+ {
+ long long int result = llroundf(tests_float[i].value.f);
+
+ if (tests_float[i].should_be == result)
+ counter++;
+ else
+ printf("llroundf test failed: value to round = %.12f result = %lld should be = %lld\n", tests_float[i].value.f, result, tests_float[i].should_be);
+ }
+ printf("%s\n", (counter < n_tests_float) ? "llroundf test failed." : "llroundf test succeded.");
+
+ return 0;
+}
diff -aprNU5 djgpp.orig/tests/cygnus/t-llroundl.c djgpp/tests/cygnus/t-llroundl.c
--- djgpp.orig/tests/cygnus/t-llroundl.c 1970-01-01 01:00:00 +0100
+++ djgpp/tests/cygnus/t-llroundl.c 2013-10-19 12:18:28 +0100
@@ -0,0 +1,147 @@
+/* Copyright (C) 2013 DJ Delorie, see COPYING.DJ for details */
+
+
+#include <stdio.h>
+#include <math.h>
+#include <libc/ieee.h>
+
+typedef struct {
+ const _longdouble_union_t value; /* test value */
+ const long long int should_be; /* result */
+} entry_t;
+
+
+static const entry_t tests_long_double[] =
+{
+ /* test value */
+ /* value should be */
+
+ /* Zeros. */
+ {{.ldt = {0x0U, 0x0U, 0x0U, 0}}, 0}, /* 0.0 */
+ {{.ldt = {0x0U, 0x0U, 0x0U, 1}}, 0}, /* -0.0 */
+
+ /* Subnormals aka denormals. */
+ {{.ldt = {0x1U, 0x0U, 0x0U, 0}}, 0}, /* Very small number. */
+ {{.ldt = {0x1U, 0x0U, 0x0U, 1}}, 0}, /* Very small -number. */
+
+ /* Normals. */
+ {{.ldt = {0x0U, 0x80000000U, 0x1U, 0}}, 0}, /* Small number. */
+ {{.ldt = {0x0U, 0x80000000U, 0x1U, 1}}, 0}, /* Small -number. */
+ {{.ldt = {0xFFFFFFFFU, 0xFFFFFFFFU, 0x7FFEU, 0}}, -9.223372036854775808E+18}, /* Big number. */
+ {{.ldt = {0xFFFFFFFFU, 0xFFFFFFFFU, 0x7FFEU, 1}}, -9.223372036854775808E+18}, /* Big -number. */
+
+ /* Infs. */
+ {{.ldt = {0x0U, 0x80000000U, 0x7FFFU, 0}}, -9.223372036854775808E+18}, /* Inf */
+ {{.ldt = {0x0U, 0x80000000U, 0x7FFFU, 1}}, -9.223372036854775808E+18}, /* -Inf */
+
+ /* NaNs. */
+ {{.ldt = {0x1U, 0x80000000U, 0x7FFFU, 0}}, -9.223372036854775808E+18}, /* SNaN */
+ {{.ldt = {0x1U, 0x80000000U, 0x7FFFU, 1}}, -9.223372036854775808E+18}, /* -SNaN */
+ {{.ldt = {0x0U, 0xFFFFFFFFU, 0x7FFFU, 0}}, -9.223372036854775808E+18}, /* QNaN */
+ {{.ldt = {0x0U, 0xFFFFFFFFU, 0x7FFFU, 1}}, -9.223372036854775808E+18}, /* -QNaN */
+
+
+ /* Number. */
+ {{.ldt = {0x2168C000U, 0xC90FDAA2U, 0x3FFFU + 0x0001U, 0}}, +3}, /* PI */
+ {{.ldt = {0x2168C000U, 0xC90FDAA2U, 0x3FFFU + 0x0001U, 1}}, -3}, /* -PI */
+
+ {{.ldt = {0x00000000U, 0xF0000000U, 0x3FFFU + 0x0U, 0}}, +2}, /* 1.875000 */
+ {{.ldt = {0x00000000U, 0xF0000000U, 0x3FFFU + 0x0U, 1}}, -2}, /* -1.875000 */
+ {{.ldt = {0x00000000U, 0xD0000000U, 0x3FFFU + 0x0U, 0}}, +2}, /* 1.625000 */
+ {{.ldt = {0x00000000U, 0xD0000000U, 0x3FFFU + 0x0U, 1}}, -2}, /* -1.625000 */
+ {{.ldt = {0xF7A0B800U, 0xC00010C6U, 0x3FFFU + 0x0U, 0}}, +2}, /* 1.500002 */
+ {{.ldt = {0xF7A0B800U, 0xC00010C6U, 0x3FFFU + 0x0U, 1}}, -2}, /* -1.500002 */
+ {{.ldt = {0x00000000U, 0xC0000000U, 0x3FFFU + 0x0U, 0}}, +2}, /* 1.500000 */
+ {{.ldt = {0x00000000U, 0xC0000000U, 0x3FFFU + 0x0U, 1}}, -2}, /* -1.500000 */
+ {{.ldt = {0x085F4800U, 0xBFFFEF39U, 0x3FFFU + 0x0U, 0}}, +1}, /* 1.499998 */
+ {{.ldt = {0x085F4800U, 0xBFFFEF39U, 0x3FFFU + 0x0U, 1}}, -1}, /* -1.499998 */
+ {{.ldt = {0x00000000U, 0xB0000000U, 0x3FFFU + 0x0U, 0}}, +1}, /* 1.375000 */
+ {{.ldt = {0x00000000U, 0xB0000000U, 0x3FFFU + 0x0U, 1}}, -1}, /* -1.375000 */
+ {{.ldt = {0x00000000U, 0x90000000U, 0x3FFFU + 0x0U, 0}}, +1}, /* 1.125000 */
+ {{.ldt = {0x00000000U, 0x90000000U, 0x3FFFU + 0x0U, 1}}, -1}, /* -1.125000 */
+
+ {{.ldt = {0x00000000U, 0x80000000U, 0x3FFFU + 0x0016U, 0}}, +4194304}, /* 4194304.000000 */
+ {{.ldt = {0x00000000U, 0x80000000U, 0x3FFFU + 0x0016U, 1}}, -4194304}, /* -4194304.000000 */
+ {{.ldt = {0x00000000U, 0x80000000U, 0x3FFFU + 0x0017U, 0}}, +8388608}, /* 8388608.000000 */
+ {{.ldt = {0x00000000U, 0x80000000U, 0x3FFFU + 0x0017U, 1}}, -8388608}, /* -8388608.000000 */
+ {{.ldt = {0x00000000U, 0x80000000U, 0x3FFFU + 0x0018U, 0}}, +16777216}, /* 16777216.000000 */
+ {{.ldt = {0x00000000U, 0x80000000U, 0x3FFFU + 0x0018U, 1}}, -16777216}, /* -16777216.000000 */
+ {{.ldt = {0x00000000U, 0x80000000U, 0x3FFFU + 0x001EU, 0}}, +1073741824}, /* 1073741824.000000 */
+ {{.ldt = {0x00000000U, 0x80000000U, 0x3FFFU + 0x001EU, 1}}, -1073741824}, /* -1073741824.000000 */
+ {{.ldt = {0x00000000U, 0xFFFFFFFEU, 0x3FFFU + 0x001EU, 0}}, +2147483647LL}, /* 2147483647.000000 */
+ {{.ldt = {0x00000000U, 0x80000000U, 0x3FFFU + 0x001FU, 1}}, -2147483648LL}, /* -2147483648.000000 */
+ {{.ldt = {0x00000000U, 0x80000000U, 0x3FFFU + 0x0020U, 0}}, +4294967296}, /* 4294967296.000000 */
+ {{.ldt = {0x00000000U, 0x80000000U, 0x3FFFU + 0x0020U, 1}}, -4294967296}, /* -4294967296.000000 */
+
+ /* Number greater than 2**63 exceeds long long int size and will be casted in an implementation defined manner. */
+ {{.ldt = {0x00000000U, 0x80000000U, 0x3FFFU + 0x003FU, 0}}, -9.223372036854775808E18}, /* 9223372036854775808.000000 */
+ {{.ldt = {0x00000000U, 0x80000000U, 0x3FFFU + 0x003FU, 1}}, -9.223372036854775808E18}, /* -9223372036854775808.000000 */
+
+ /* Number less than 0.5 will be truncated to 0. */
+ {{.ldt = {0xC42F9800U, 0xFFBC98FFU, 0x3FFFU + 0xFFFFFFFEU, 0}}, 0}, /* 0.4994857609 */
+ {{.ldt = {0xC42F9800U, 0xFFBC98FFU, 0x3FFFU + 0xFFFFFFFEU, 1}}, -0}, /* -0.4994857609 */
+ {{.ldt = {0x8D4FE000U, 0x83126E97U, 0x3FFFU + 0xFFFFFFF6U, 0}}, 0}, /* 0.0010000000 */
+ {{.ldt = {0x8D4FE000U, 0x83126E97U, 0x3FFFU + 0xFFFFFFF6U, 1}}, -0}, /* -0.0010000000 */
+
+ /* Number greater than 0.5 and less than 1 will be rounded to 1. */
+ {{.ldt = {0xC37A4000U, 0xFCD6E47DU, 0x3FFFU + 0xFFFFFFFFU, 0}}, 1}, /* 0.9876540000 */
+ {{.ldt = {0xC37A4000U, 0xFCD6E47DU, 0x3FFFU + 0xFFFFFFFFU, 1}}, -1}, /* -0.9876540000 */
+ {{.ldt = {0xB2B29800U, 0x80000101U, 0x3FFFU + 0xFFFFFFFFU, 0}}, 1}, /* 0.5000000600 */
+ {{.ldt = {0xB2B29800U, 0x80000101U, 0x3FFFU + 0xFFFFFFFFU, 1}}, -1}, /* -0.5000000600 */
+ {{.ldt = {0x00000000U, 0x80000000U, 0x3FFFU + 0xFFFFFFFFU, 0}}, 1}, /* 0.5000000000 */
+ {{.ldt = {0x00000000U, 0x80000000U, 0x3FFFU + 0xFFFFFFFFU, 1}}, -1}, /* -0.5000000000 */
+
+ /* Number greather than 1 and less than 2**31 will be rounded accordingly. */
+ {{.ldt = {0x00000000U, 0x80000000U, 0x3FFFU + 0x0000U, 0}}, 1}, /* 1.0000000000 */
+ {{.ldt = {0x00000000U, 0x80000000U, 0x3FFFU + 0x0000U, 1}}, -1}, /* -1.0000000000 */
+ {{.ldt = {0xF7A0B800U, 0x800010C6U, 0x3FFFU + 0x0000U, 0}}, 1}, /* 1.0000020000 */
+ {{.ldt = {0xF7A0B800U, 0x800010C6U, 0x3FFFU + 0x0000U, 1}}, -1}, /* -1.0000020000 */
+ {{.ldt = {0x00000000U, 0x80001800U, 0x3FFFU + 0x0010U, 0}}, 65536}, /* 65536.1875000000 */
+ {{.ldt = {0x00000000U, 0x80001800U, 0x3FFFU + 0x0010U, 1}}, -65536}, /* -65536.1875000000 */
+ {{.ldt = {0x00000000U, 0x80004000U, 0x3FFFU + 0x0010U, 0}}, 65537}, /* 65536.5000000000 */
+ {{.ldt = {0x00000000U, 0x80004000U, 0x3FFFU + 0x0010U, 1}}, -65537}, /* -65536.5000000000 */
+ {{.ldt = {0x00000000U, 0x80004D00U, 0x3FFFU + 0x0010U, 0}}, 65537}, /* 65536.6015625000 */
+ {{.ldt = {0x00000000U, 0x80004D00U, 0x3FFFU + 0x0010U, 1}}, -65537}, /* -65536.6015625000 */
+ {{.ldt = {0x00000000U, 0xFFFFFF00U, 0x3FFFU + 0x0016U, 0}}, 8388608}, /* 8388607.5000000000 */
+ {{.ldt = {0x00000000U, 0xFFFFFF00U, 0x3FFFU + 0x0016U, 1}}, -8388608}, /* -8388607.5000000000 */
+ {{.ldt = {0x00000000U, 0x80000500U, 0x3FFFU + 0x0014U, 0}}, 1048577}, /* 1048576.6250000000 */
+ {{.ldt = {0x00000000U, 0x80000500U, 0x3FFFU + 0x0014U, 1}}, -1048577}, /* -1048576.6250000000 */
+ {{.ldt = {0x00000000U, 0xFFFFFFFEU, 0x3FFFU + 0x001EU, 0}}, 2147483647}, /* 2147483647.0000000000 */
+ {{.ldt = {0x00000000U, 0xFFFFFFFEU, 0x3FFFU + 0x001EU, 1}}, -2147483647}, /* -2147483647.0000000000 */
+
+ /* Number greather than 2**31 and less than 2**63 will be rounded accordingly. */
+ {{.ldt = {0x00000000U, 0x80000000U, 0x3FFFU + 0x001FU, 0}}, 2147483648LL}, /* 2147483648.0000000000 */
+ {{.ldt = {0x00000000U, 0x80000000U, 0x3FFFU + 0x001FU, 1}}, -2147483648LL}, /* -2147483648.0000000000 */
+ {{.ldt = {0xFFFFFFFEU, 0xFFFFFFFFU, 0x3FFFU + 0x003EU, 0}}, 9223372036854775807}, /* 9223372036854775807.0000000000 */
+ {{.ldt = {0xFFFFFFFEU, 0xFFFFFFFFU, 0x3FFFU + 0x003EU, 1}}, -9223372036854775807}, /* -9223372036854775807.0000000000 */
+ {{.ldt = {0x00000067U, 0x80000000U, 0x3FFFU + 0x0037U, 0}}, 36028797018963968}, /* 36028797018963968.4023437500 */
+ {{.ldt = {0x00000067U, 0x80000000U, 0x3FFFU + 0x0037U, 1}}, -36028797018963968}, /* -36028797018963968.4023437500 */
+ {{.ldt = {0x00000080U, 0x80000000U, 0x3FFFU + 0x0037U, 0}}, 36028797018963969}, /* 36028797018963968.5000000000000000 */
+ {{.ldt = {0x00000080U, 0x80000000U, 0x3FFFU + 0x0037U, 1}}, -36028797018963969}, /* -36028797018963968.5000000000000000 */
+ {{.ldt = {0x00000083U, 0x80000000U, 0x3FFFU + 0x0037U, 0}}, 36028797018963969}, /* 36028797018963968.5117187500000000 */
+ {{.ldt = {0x00000083U, 0x80000000U, 0x3FFFU + 0x0037U, 1}}, -36028797018963969}, /* -36028797018963968.5117187500000000 */
+
+ {{.ldt = {0x00000000U, 0x80000000U, 0x3FFFU + 0x003FU, 0}}, -9223372036854775808ULL}, /* 9223372036854775808.0000000000000000 */
+ {{.ldt = {0x00000000U, 0x80000000U, 0x3FFFU + 0x003FU, 1}}, -9223372036854775808ULL}, /* 9223372036854775808.0000000000000000 */
+};
+
+static const size_t n_tests_long_double = sizeof(tests_long_double) / sizeof(tests_long_double[0]);
+
+
+int main(void)
+{
+ unsigned int i, counter;
+
+ for (counter = i = 0; i < n_tests_long_double; i++)
+ {
+ long long int result = llroundl(tests_long_double[i].value.ld);
+
+ if (tests_long_double[i].should_be == result)
+ counter++;
+ else
+ printf("llroundl test failed: value to round = %.12Lg result = %lld should be = %lld\n", tests_long_double[i].value.ld, result, tests_long_double[i].should_be);
+ }
+ printf("%s\n", (counter < n_tests_long_double) ? "llroundl test failed." : "llroundl test succeded.");
+
+ return 0;
+}
diff -aprNU5 djgpp.orig/tests/cygnus/t-lround.c djgpp/tests/cygnus/t-lround.c
--- djgpp.orig/tests/cygnus/t-lround.c 1970-01-01 01:00:00 +0100
+++ djgpp/tests/cygnus/t-lround.c 2013-10-14 22:40:02 +0100
@@ -0,0 +1,180 @@
+/* Copyright (C) 2013 DJ Delorie, see COPYING.DJ for details */
+
+
+#include <stdio.h>
+#include <math.h>
+#include <libc/ieee.h>
+
+typedef struct {
+ const _double_union_t value; /* test value */
+ const long int should_be; /* result */
+} entry_t;
+
+
+static const entry_t tests_double[] =
+{
+ /* test value */
+ /* value should be */
+
+ /* Zeros. */
+ {{.dt = {0x0U, 0x0U, 0x0U, 0}}, 0}, /* 0.0 */
+ {{.dt = {0x0U, 0x0U, 0x0U, 1}}, 0}, /* -0.0 */
+
+ /* Subnormals aka denormals. */
+ {{.dt = {0x1U, 0x0U, 0x0U, 0}}, 0}, /* Very small number. */
+ {{.dt = {0x1U, 0x0U, 0x0U, 1}}, 0}, /* Very small -number. */
+
+ /* Normals. */
+ {{.dt = {0x1U, 0x0U, 0x1U, 0}}, 0}, /* Small number. */
+ {{.dt = {0x1U, 0x0U, 0x1U, 1}}, 0}, /* Small -number. */
+ {{.dt = {0xFFFFFFFFU, 0x7FFFFU, 0x7FEU, 0}}, -2147483648LL}, /* Big number. */
+ {{.dt = {0xFFFFFFFFU, 0x7FFFFU, 0x7FEU, 1}}, -2147483648LL}, /* Big -number. */
+
+ /* Infs. */
+ {{.dt = {0x0U, 0x0U, 0x7FFU, 0}}, -2147483648LL}, /* Inf */
+ {{.dt = {0x0U, 0x0U, 0x7FFU, 1}}, -2147483648LL}, /* -Inf */
+
+ /* NaNs. */
+ {{.dt = {0x1U, 0x0U, 0x7FFU, 0}}, -2147483648LL}, /* SNaN */
+ {{.dt = {0x1U, 0x0U, 0x7FFU, 1}}, -2147483648LL}, /* -SNaN */
+ {{.dt = {0x0U, 0xFFFFFU, 0x7FFU, 1}}, -2147483648LL}, /* QNaN */
+ {{.dt = {0x0U, 0xFFFFFU, 0x7FFU, 0}}, -2147483648LL}, /* -QNaN */
+
+
+ /* Number. */
+ {{.dt = {0x54442D18U, 0x921FBU, 0x3FFU + 0x001U, 0}}, +3}, /* PI */
+ {{.dt = {0x54442D18U, 0x921FBU, 0x3FFU + 0x001U, 1}}, -3}, /* -PI */
+
+ {{.dt = {0x00000000U, 0xE0000U, 0x3FFU + 0x0U, 0}}, +2}, /* 1.875000 */
+ {{.dt = {0x00000000U, 0xE0000U, 0x3FFU + 0x0U, 1}}, -2}, /* -1.875000 */
+ {{.dt = {0x00000000U, 0xA0000U, 0x3FFU + 0x0U, 0}}, +2}, /* 1.625000 */
+ {{.dt = {0x00000000U, 0xA0000U, 0x3FFU + 0x0U, 1}}, -2}, /* -1.625000 */
+ {{.dt = {0x18DEF417U, 0x80002U, 0x3FFU + 0x0U, 0}}, +2}, /* 1.500002 */
+ {{.dt = {0x18DEF417U, 0x80002U, 0x3FFU + 0x0U, 1}}, -2}, /* -1.500002 */
+ {{.dt = {0x00000000U, 0x80000U, 0x3FFU + 0x0U, 0}}, +2}, /* 1.500000 */
+ {{.dt = {0x00000000U, 0x80000U, 0x3FFU + 0x0U, 1}}, -2}, /* -1.500000 */
+ {{.dt = {0xE7210BE9U, 0x7F9FDU, 0x3FFU + 0x0U, 0}}, +1}, /* 1.499998 */
+ {{.dt = {0xE7210BE9U, 0x7F9FDU, 0x3FFU + 0x0U, 1}}, -1}, /* -1.499998 */
+ {{.dt = {0x00000000U, 0x60000U, 0x3FFU + 0x0U, 0}}, +1}, /* 1.375000 */
+ {{.dt = {0x00000000U, 0x60000U, 0x3FFU + 0x0U, 1}}, -1}, /* -1.375000 */
+ {{.dt = {0x00000000U, 0x20000U, 0x3FFU + 0x0U, 0}}, +1}, /* 1.125000 */
+ {{.dt = {0x00000000U, 0x20000U, 0x3FFU + 0x0U, 1}}, -1}, /* -1.125000 */
+
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0x016U, 0}}, +4194304}, /* 4194304.000000 */
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0x016U, 1}}, -4194304}, /* -4194304.000000 */
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0x017U, 0}}, +8388608}, /* 8388608.000000 */
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0x017U, 1}}, -8388608}, /* -8388608.000000 */
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0x018U, 0}}, +16777216}, /* 16777216.000000 */
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0x018U, 1}}, -16777216}, /* -16777216.000000 */
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0x01EU, 0}}, +1073741824}, /* 1073741824.000000 */
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0x01EU, 1}}, -1073741824}, /* -1073741824.000000 */
+ {{.dt = {0xFFC00000U, 0xFFFFFU, 0x3FFU + 0x01EU, 0}}, +2147483647LL}, /* 2147483647.000000 */
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0x01FU, 1}}, -2147483648LL}, /* -2147483648.000000 */
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0x020U, 0}}, -2147483648LL}, /* 4294967296.000000 */
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0x020U, 1}}, -2147483648LL}, /* -4294967296.000000 */
+
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0x01FU, 0}}, -2147483648LL}, /* 2147483648.000000 */
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0x01FU, 1}}, -2147483648LL}, /* -2147483648.000000 */
+ {{.dt = {0xF9ADD3C1U, 0x00001U, 0x3FFU + 0x013U, 0}}, 524289}, /* 524288.9876543210 */
+ {{.dt = {0xF9ADD3C1U, 0x00001U, 0x3FFU + 0x013U, 1}}, -524289}, /* -524288.9876543210 */
+ {{.dt = {0x22C27E88U, 0x00001U, 0x3FFU + 0x013U, 0}}, 524289}, /* 524288.5678901235 */
+ {{.dt = {0x22C27E88U, 0x00001U, 0x3FFU + 0x013U, 1}}, -524289}, /* -524288.5678901235 */
+ {{.dt = {0xE9E03FDAU, 0x00000U, 0x3FFU + 0x013U, 0}}, 524288}, /* 524288.4567890123 */
+ {{.dt = {0xE9E03FDAU, 0x00000U, 0x3FFU + 0x013U, 1}}, -524288}, /* -524288.4567890123 */
+ {{.dt = {0x06522C3EU, 0x00000U, 0x3FFU + 0x013U, 0}}, 524288}, /* 524288.0123456789 */
+ {{.dt = {0x06522C3EU, 0x00000U, 0x3FFU + 0x013U, 1}}, -524288}, /*- 524288.0123456789 */
+
+ {{.dt = {0x00000000U, 0xC0000U, 0x3FFU + 0x000U, 0}}, 2}, /* 1.7500000000 */
+ {{.dt = {0x00000000U, 0xC0000U, 0x3FFU + 0x000U, 1}}, -2}, /* -1.7500000000 */
+ {{.dt = {0x00000000U, 0x80000U, 0x3FFU + 0x000U, 0}}, 2}, /* 1.5000000000 */
+ {{.dt = {0x00000000U, 0x80000U, 0x3FFU + 0x000U, 1}}, -2}, /* -1.5000000000 */
+ {{.dt = {0x00000000U, 0x40000U, 0x3FFU + 0x000U, 0}}, 1}, /* 1.2500000000 */
+ {{.dt = {0x00000000U, 0x40000U, 0x3FFU + 0x000U, 1}}, -1}, /* -1.2500000000 */
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0x000U, 0}}, 1}, /* 1.0000000000 */
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0x000U, 1}}, -1}, /* -1.0000000000 */
+ {{.dt = {0x00000000U, 0x80000U, 0x3FFU + 0xFFFFFFFFU, 0}}, 1}, /* 0.7500000000 */
+ {{.dt = {0x00000000U, 0x80000U, 0x3FFU + 0xFFFFFFFFU, 1}}, -1}, /* -0.7500000000 */
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0xFFFFFFFFU, 0}}, 1}, /* 0.5000000000 */
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0xFFFFFFFFU, 1}}, -1}, /* -0.5000000000 */
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0xFFFFFFFEU, 0}}, 0}, /* 0.2500000000 */
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0xFFFFFFFEU, 1}}, -0}, /* -0.2500000000 */
+ {{.dt = {0xF8FAB5E6U, 0x948B0U, 0x3FFU + 0xFFFFFFF9U, 0}}, 0}, /* 0.0123456789 */
+ {{.dt = {0xF8FAB5E6U, 0x948B0U, 0x3FFU + 0xFFFFFFF9U, 1}}, -0}, /* -0.0123456789 */
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0xFFFFFC01U, 0}}, 0}, /* 0.0000000000 */
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0xFFFFFC01U, 1}}, -0}, /* -0.0000000000 */
+
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0x014U, 0}}, 1048576}, /* 1048576.0000000000 */
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0x014U, 1}}, -1048576}, /* -1048576.0000000000 */
+ {{.dt = {0x40000000U, 0x00000U, 0x3FFU + 0x014U, 0}}, 1048576}, /* 1048576.2500000000 */
+ {{.dt = {0x40000000U, 0x00000U, 0x3FFU + 0x014U, 1}}, -1048576}, /* -1048576.2500000000 */
+ {{.dt = {0x80000000U, 0x00000U, 0x3FFU + 0x014U, 0}}, 1048577}, /* 1048576.5000000000 */
+ {{.dt = {0x80000000U, 0x00000U, 0x3FFU + 0x014U, 1}}, -1048577}, /* -1048576.5000000000 */
+ {{.dt = {0xC0000000U, 0x00000U, 0x3FFU + 0x014U, 0}}, 1048577}, /* 1048576.7500000000 */
+ {{.dt = {0xC0000000U, 0x00000U, 0x3FFU + 0x014U, 1}}, -1048577}, /* -1048576.7500000000 */
+
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0x015U, 0}}, 2097152}, /* 2097152.0000000000 */
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0x015U, 1}}, -2097152}, /* -2097152.0000000000 */
+ {{.dt = {0x20000000U, 0x00000U, 0x3FFU + 0x015U, 0}}, 2097152}, /* 2097152.2500000000 */
+ {{.dt = {0x20000000U, 0x00000U, 0x3FFU + 0x015U, 1}}, -2097152}, /* -2097152.2500000000 */
+ {{.dt = {0x40000000U, 0x00000U, 0x3FFU + 0x015U, 0}}, 2097153}, /* 2097152.5000000000 */
+ {{.dt = {0x40000000U, 0x00000U, 0x3FFU + 0x015U, 1}}, -2097153}, /* -2097152.5000000000 */
+ {{.dt = {0x60000000U, 0x00000U, 0x3FFU + 0x015U, 0}}, 2097153}, /* 2097152.7500000000 */
+ {{.dt = {0x60000000U, 0x00000U, 0x3FFU + 0x015U, 1}}, -2097153}, /* -2097152.7500000000 */
+
+ /* Number greater than 2**31 exceeds long int size and will be casted in an implementation defined manner. */
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0x01FU, 0}}, -2147483648LL}, /* 2147483648.000000 */
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0x01FU, 0}}, -2147483648LL}, /* -2147483648.000000 */
+
+ /* Number less than 0.5 will be truncated to 0. */
+ {{.dt = {0x1FF885F3U, 0xFF793U, 0x3FFU + 0xFFFFFFFEU, 0}}, 0}, /* 0.4994857609 */
+ {{.dt = {0x1FF885F3U, 0xFF793U, 0x3FFU + 0xFFFFFFFEU, 1}}, -0}, /* -0.4994857609 */
+ {{.dt = {0xD2F1A9FCU, 0x0624DU, 0x3FFU + 0xFFFFFFF6U, 0}}, 0}, /* 0.0010000000 */
+ {{.dt = {0xD2F1A9FCU, 0x0624DU, 0x3FFU + 0xFFFFFFF6U, 1}}, -0}, /* -0.0010000000 */
+
+ /* Number greater than 0.5 and less than 1 will be rounded to 1. */
+ {{.dt = {0x8FB86F48U, 0xF9ADCU, 0x3FFU + 0xFFFFFFFFU, 0}}, 1}, /* 0.9876540000 */
+ {{.dt = {0x8FB86F48U, 0xF9ADCU, 0x3FFU + 0xFFFFFFFFU, 1}}, -1}, /* -0.9876540000 */
+ {{.dt = {0x20365653U, 0x00000U, 0x3FFU + 0xFFFFFFFFU, 0}}, 1}, /* 0.5000000600 */
+ {{.dt = {0x20365653U, 0x00000U, 0x3FFU + 0xFFFFFFFFU, 1}}, -1}, /* -0.5000000600 */
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0xFFFFFFFFU, 0}}, 1}, /* -0.5000000000 */
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0xFFFFFFFFU, 1}}, -1}, /* -0.5000000000 */
+
+ /* Number greather than 1 and less than 2**31 will be rounded accordingly. */
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0x000U, 0}}, 1}, /* 1.0000000000 */
+ {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0x000U, 1}}, -1}, /* -1.0000000000 */
+ {{.dt = {0x18DEF417U, 0x00002U, 0x3FFU + 0x000U, 0}}, 1}, /* 1.0000020000 */
+ {{.dt = {0x18DEF417U, 0x00002U, 0x3FFU + 0x000U, 1}}, -1}, /* -1.0000020000 */
+ {{.dt = {0x00000000U, 0x00003U, 0x3FFU + 0x010U, 0}}, 65536}, /* 65536.1875000000 */
+ {{.dt = {0x00000000U, 0x00003U, 0x3FFU + 0x010U, 1}}, -65536}, /* -65536.1875000000 */
+ {{.dt = {0x00000000U, 0x00008U, 0x3FFU + 0x010U, 0}}, 65537}, /* 65536.5000000000 */
+ {{.dt = {0x00000000U, 0x00008U, 0x3FFU + 0x010U, 1}}, -65537}, /* -65536.5000000000 */
+ {{.dt = {0xA0000000U, 0x00009U, 0x3FFU + 0x010U, 0}}, 65537}, /* 65536.6015625000 */
+ {{.dt = {0xA0000000U, 0x00009U, 0x3FFU + 0x010U, 1}}, -65537}, /* -65536.6015625000 */
+ {{.dt = {0xE0000000U, 0xFFFFFU, 0x3FFU + 0x016U, }}, 8388608}, /* 8388607.5000000000 */
+ {{.dt = {0xE0000000U, 0xFFFFFU, 0x3FFU + 0x016U, 1}}, -8388608}, /* -8388607.5000000000 */
+ {{.dt = {0xA0000000U, 0x00000U, 0x3FFU + 0x014U, 0}}, 1048577}, /* 1048576.6250000000 */
+ {{.dt = {0xA0000000U, 0x00000U, 0x3FFU + 0x014U, 1}}, -1048577}, /* -1048576.6250000000 */
+ {{.dt = {0xFFC00000U, 0xFFFFFU, 0x3FFU + 0x01EU, 0}}, 2147483647}, /* 2147483647.0000000000 */
+ {{.dt = {0xFFC00000U, 0xFFFFFU, 0x3FFU + 0x01EU, 1}}, -2147483647}, /* -2147483647.0000000000 */
+};
+
+static const size_t n_tests_double = sizeof(tests_double) / sizeof(tests_double[0]);
+
+
+int main(void)
+{
+ unsigned int i, counter;
+
+ for (counter = i = 0; i < n_tests_double; i++)
+ {
+ long int result = lround(tests_double[i].value.d);
+
+ if (tests_double[i].should_be == result)
+ counter++;
+ else
+ printf("lround test failed: value to round = %.6g result = %ld should be = %ld\n", tests_double[i].value.d, result, tests_double[i].should_be);
+ }
+ printf("%s\n", (counter < n_tests_double) ? "lround test failed." : "lround test succeded.");
+
+ return 0;
+}
diff -aprNU5 djgpp.orig/tests/cygnus/t-lroundf.c djgpp/tests/cygnus/t-lroundf.c
--- djgpp.orig/tests/cygnus/t-lroundf.c 1970-01-01 01:00:00 +0100
+++ djgpp/tests/cygnus/t-lroundf.c 2013-10-14 22:40:02 +0100
@@ -0,0 +1,137 @@
+/* Copyright (C) 2013 DJ Delorie, see COPYING.DJ for details */
+
+
+#include <stdio.h>
+#include <math.h>
+#include <libc/ieee.h>
+
+typedef struct {
+ const _float_union_t value; /* test value */
+ const long int should_be; /* result */
+} entry_t;
+
+static const entry_t tests_float[] =
+{
+ /* test value */
+ /* value should be */
+
+ /* Zeros. */
+ {{.ft = {0x0U, 0x0U, 0}}, 0}, /* 0.0 */
+ {{.ft = {0x0U, 0x0U, 1}}, 0}, /* -0.0 */
+
+ /* Subnormals aka denormals. */
+ {{.ft = {0x1U, 0x0U, 0}}, 0}, /* Very small number. */
+ {{.ft = {0x1U, 0x0U, 1}}, 0}, /* Very small -number. */
+
+ /* Normals. */
+ {{.ft = {0x1U, 0x1U, 0}}, 0}, /* Small number. */
+ {{.ft = {0x1U, 0x1U, 1}}, 0}, /* Small -number. */
+ {{.ft = {0xFFFFU, 0xFEU, 0}}, -2147483648LL}, /* Big number. */
+ {{.ft = {0xFFFFU, 0xFEU, 1}}, -2147483648LL}, /* Big -number. */
+
+ /* Infs. */
+ {{.ft = {0x0U, 0xFFU, 0}}, -2147483648LL}, /* Inf */
+ {{.ft = {0x0U, 0xFFU, 1}}, -2147483648LL}, /* -Inf */
+
+ /* NaNs. */
+ {{.ft = {0x1U, 0xFFU, 0}}, -2147483648LL}, /* SNaN */
+ {{.ft = {0x1U, 0xFFU, 1}}, -2147483648LL}, /* -SNaN */
+ {{.ft = {0x7FFFFFU, 0xFFU, 0}}, -2147483648LL}, /* QNaN */
+ {{.ft = {0x7FFFFFU, 0xFFU, 1}}, -2147483648LL}, /* -QNaN */
+
+ /* Numbers. */
+ {{.ft = {0x490FDBU, 0x80U, 0}}, +3}, /* PI */
+ {{.ft = {0x490FDBU, 0x80U, 1}}, -3}, /* -PI */
+
+ {{.ft = {0x700000U, 0x7FU, 0}}, +2}, /* 1.875000 */
+ {{.ft = {0x700000U, 0x7FU, 1}}, -2}, /* -1.875000 */
+ {{.ft = {0x500000U, 0x7FU, 0}}, +2}, /* 1.625000 */
+ {{.ft = {0x500000U, 0x7FU, 1}}, -2}, /* -1.625000 */
+ {{.ft = {0x40000FU, 0x7FU, 0}}, +2}, /* 1.500002 */
+ {{.ft = {0x40000FU, 0x7FU, 1}}, -2}, /* -1.500002 */
+ {{.ft = {0x400000U, 0x7FU, 0}}, +2}, /* 1.500000 */
+ {{.ft = {0x400000U, 0x7FU, 1}}, -2}, /* -1.500000 */
+ {{.ft = {0x3FFFF0U, 0x7FU, 0}}, +1}, /* 1.499998 */
+ {{.ft = {0x3FFFF0U, 0x7FU, 1}}, -1}, /* -1.499998 */
+ {{.ft = {0x300000U, 0x7FU, 0}}, +1}, /* 1.375000 */
+ {{.ft = {0x300000U, 0x7FU, 1}}, -1}, /* -1.375000 */
+ {{.ft = {0x100000U, 0x7FU, 0}}, +1}, /* 1.125000 */
+ {{.ft = {0x100000U, 0x7FU, 1}}, -1}, /* -1.125000 */
+
+ {{.ft = {0x000000U, 0x7FU + 0x16U, 0}}, +4194304}, /* 4194304.000000 */
+ {{.ft = {0x000000U, 0x7FU + 0x16U, 1}}, -4194304}, /* -4194304.000000 */
+ {{.ft = {0x000000U, 0x7FU + 0x17U, 0}}, +8388608}, /* 8388608.000000 */
+ {{.ft = {0x000000U, 0x7FU + 0x17U, 1}}, -8388608}, /* -8388608.000000 */
+ {{.ft = {0x000000U, 0x7FU + 0x18U, 0}}, +16777216}, /* 16777216.000000 */
+ {{.ft = {0x000000U, 0x7FU + 0x18U, 1}}, -16777216}, /* -16777216.000000 */
+
+ {{.ft = {0x000000U, 0x7FU + 0x1EU, 0}}, +1073741824}, /* 1073741824.000000 */
+ {{.ft = {0x000000U, 0x7FU + 0x1EU, 1}}, -1073741824}, /* -1073741824.000000 */
+ {{.ft = {0x000000U, 0x7FU + 0x1FU, 0}}, +2147483648LL}, /* 2147483648.000000 */
+ {{.ft = {0x000000U, 0x7FU + 0x1FU, 1}}, -2147483648LL}, /* -2147483648.000000 */
+ {{.ft = {0x000000U, 0x7FU + 0x20U, 0}}, -2147483648LL}, /* 4294967296.000000 */
+ {{.ft = {0x000000U, 0x7FU + 0x20U, 1}}, -2147483648LL}, /* -4294967296.000000 */
+
+ /* Different mantissa patterns. */
+ {{.ft = {0x7FFFFFU, 0x96U, 0}}, +16777215}, /* 16777215.000000 */
+ {{.ft = {0x7FF000U, 0x95U, 0}}, +8386560}, /* 8386560.000000 */
+ {{.ft = {0x1555FFU, 0x8DU, 0}}, +19115}, /* 19115.000000 */
+ {{.ft = {0x7FF000U, 0x96U, 1}}, -16773120}, /* -16773120.000000 */
+ {{.ft = {0x7FFFFEU, 0x95U, 1}}, -8388607}, /* -8388607.000000 */
+ {{.ft = {0x1555FFU, 0x8DU, 1}}, -19115}, /* -19115.000000 */
+
+ /* Number greater than 2**31 exceeds long int size and will be casted in an implementation defined manner. */
+ {{.ft = {0x000000U, 0x7FU + 0x1FU, 0}}, +2147483648LL}, /* 2147483648.000000 */
+ {{.ft = {0x000000U, 0x7FU + 0x1FU, 1}}, -2147483648LL}, /* -2147483648.000000 */
+
+ /* Number less than 0.5 will be truncated to 0. */
+ {{.ft = {0x7FBC99U, 0x7FU + 0xFFFFFFFEU, 0}}, 0}, /* 0.4994857609 */
+ {{.ft = {0x7FBC99U, 0x7FU + 0xFFFFFFFEU, 1}}, -0}, /* -0.4994857609 */
+ {{.ft = {0x03126FU, 0x7FU + 0xFFFFFFF6U, 0}}, 0}, /* 0.001000 */
+ {{.ft = {0x03126FU, 0x7FU + 0xFFFFFFF6U, 1}}, -0}, /* -0.001000 */
+
+ /* Number greater than 0.5 and less than 1 will be rounded to 1. */
+ {{.ft = {0x7CD6EAU, 0x7FU + 0xFFFFFFFFU, 0}}, 1}, /* 0.987654 */
+ {{.ft = {0x7CD6EAU, 0x7FU + 0xFFFFFFFFU, 1}}, -1}, /* -0.987654 */
+ {{.ft = {0x000001U, 0x7FU + 0xFFFFFFFFU, 0}}, 1}, /* 0.50000006 */
+ {{.ft = {0x000001U, 0x7FU + 0xFFFFFFFFU, 1}}, -1}, /* -0.50000006 */
+ {{.ft = {0x000000U, 0x7FU + 0xFFFFFFFFU, 0}}, 1}, /* 0.500000 */
+ {{.ft = {0x000000U, 0x7FU + 0xFFFFFFFFU, 1}}, -1}, /* -0.500000 */
+
+ /* Number greather than 1 and less than 2**23 will be rounded accordingly. */
+ {{.ft = {0x000000U, 0x7FU + 0x00U, 0}}, 1}, /* 1.0000000000 */
+ {{.ft = {0x000000U, 0x7FU + 0x00U, 1}}, -1}, /* 1.0000000000 */
+ {{.ft = {0x00000FU, 0x7FU + 0x00U, 0}}, 1}, /* 1.000002 */
+ {{.ft = {0x00000FU, 0x7FU + 0x00U, 1}}, -1}, /* 1.000002 */
+ {{.ft = {0x000018U, 0x7FU + 0x10U, 0}}, 65536}, /* 65536.1875000000 */
+ {{.ft = {0x000018U, 0x7FU + 0x10U, 1}}, -65536}, /* -65536.1875000000 */
+ {{.ft = {0x000040U, 0x7FU + 0x10U, 0}}, 65537}, /* 65536.5000000 */
+ {{.ft = {0x000040U, 0x7FU + 0x10U, 1}}, -65537}, /* -65536.5000000 */
+ {{.ft = {0x00004DU, 0x7FU + 0x10U, 0}}, 65537}, /* 65536.6015625000 */
+ {{.ft = {0x00004DU, 0x7FU + 0x10U, 1}}, -65537}, /* -65536.6015625000 */
+ {{.ft = {0x7FFFFFU, 0x7FU + 0x16U, 0}}, 8388608}, /* 8388607.5000000000 */
+ {{.ft = {0x7FFFFFU, 0x7FU + 0x16U, 1}}, -8388608}, /* -8388607.5000000000 */
+ {{.ft = {0x000005U, 0x7FU + 0x14U, 0}}, 1048577}, /* 1048576.6250000000 */
+ {{.ft = {0x000005U, 0x7FU + 0x14U, 1}}, -1048577}, /* -1048576.6250000000 */
+};
+
+static const size_t n_tests_float = sizeof(tests_float) / sizeof(tests_float[0]);
+
+
+int main(void)
+{
+ unsigned int i, counter;
+
+ for (counter = i = 0; i < n_tests_float; i++)
+ {
+ long int result = lroundf(tests_float[i].value.f);
+
+ if (tests_float[i].should_be == result)
+ counter++;
+ else
+ printf("lroundf test failed: value to round = %.12f result = %ld should be = %ld\n", tests_float[i].value.f, result, tests_float[i].should_be);
+ }
+ printf("%s\n", (counter < n_tests_float) ? "lroundf test failed." : "lroundf test succeded.");
+
+ return 0;
+}
diff -aprNU5 djgpp.orig/tests/cygnus/t-lroundl.c djgpp/tests/cygnus/t-lroundl.c
--- djgpp.orig/tests/cygnus/t-lroundl.c 1970-01-01 01:00:00 +0100
+++ djgpp/tests/cygnus/t-lroundl.c 2013-10-14 22:40:02 +0100
@@ -0,0 +1,131 @@
+/* Copyright (C) 2013 DJ Delorie, see COPYING.DJ for details */
+
+
+#include <stdio.h>
+#include <math.h>
+#include <libc/ieee.h>
+
+typedef struct {
+ const _longdouble_union_t value; /* test value */
+ const long int should_be; /* result */
+} entry_t;
+
+
+static const entry_t tests_long_double[] =
+{
+ /* test value */
+ /* value should be */
+
+ /* Zeros. */
+ {{.ldt = {0x0U, 0x0U, 0x0U, 0}}, 0}, /* 0.0 */
+ {{.ldt = {0x0U, 0x0U, 0x0U, 1}}, 0}, /* -0.0 */
+
+ /* Subnormals aka denormals. */
+ {{.ldt = {0x1U, 0x0U, 0x0U, 0}}, 0}, /* Very small number. */
+ {{.ldt = {0x1U, 0x0U, 0x0U, 1}}, 0}, /* Very small -number. */
+
+ /* Normals. */
+ {{.ldt = {0x0U, 0x80000000U, 0x1U, 0}}, 0}, /* Small number. */
+ {{.ldt = {0x0U, 0x80000000U, 0x1U, 1}}, 0}, /* Small -number. */
+ {{.ldt = {0xFFFFFFFFU, 0xFFFFFFFFU, 0x7FFEU, 0}}, -2147483648LL}, /* Big number. */
+ {{.ldt = {0xFFFFFFFFU, 0xFFFFFFFFU, 0x7FFEU, 1}}, -2147483648LL}, /* Big -number. */
+
+ /* Infs. */
+ {{.ldt = {0x0U, 0x80000000U, 0x7FFFU, 0}}, -2147483648LL}, /* Inf */
+ {{.ldt = {0x0U, 0x80000000U, 0x7FFFU, 1}}, -2147483648LL}, /* -Inf */
+
+ /* NaNs. */
+ {{.ldt = {0x1U, 0x80000000U, 0x7FFFU, 0}}, -2147483648LL}, /* SNaN */
+ {{.ldt = {0x1U, 0x80000000U, 0x7FFFU, 1}}, -2147483648LL}, /* -SNaN */
+ {{.ldt = {0x0U, 0xFFFFFFFFU, 0x7FFFU, 0}}, -2147483648LL}, /* QNaN */
+ {{.ldt = {0x0U, 0xFFFFFFFFU, 0x7FFFU, 1}}, -2147483648LL}, /* -QNaN */
+
+ /* Number. */
+ {{.ldt = {0x2168C000U, 0xC90FDAA2U, 0x3FFFU + 0x0001U, 0}}, +3}, /* PI */
+ {{.ldt = {0x2168C000U, 0xC90FDAA2U, 0x3FFFU + 0x0001U, 1}}, -3}, /* -PI */
+
+ {{.ldt = {0x00000000U, 0xF0000000U, 0x3FFFU + 0x0U, 0}}, +2}, /* 1.875000 */
+ {{.ldt = {0x00000000U, 0xF0000000U, 0x3FFFU + 0x0U, 1}}, -2}, /* -1.875000 */
+ {{.ldt = {0x00000000U, 0xD0000000U, 0x3FFFU + 0x0U, 0}}, +2}, /* 1.625000 */
+ {{.ldt = {0x00000000U, 0xD0000000U, 0x3FFFU + 0x0U, 1}}, -2}, /* -1.625000 */
+ {{.ldt = {0xF7A0B800U, 0xC00010C6U, 0x3FFFU + 0x0U, 0}}, +2}, /* 1.500002 */
+ {{.ldt = {0xF7A0B800U, 0xC00010C6U, 0x3FFFU + 0x0U, 1}}, -2}, /* -1.500002 */
+ {{.ldt = {0x00000000U, 0xC0000000U, 0x3FFFU + 0x0U, 0}}, +2}, /* 1.500000 */
+ {{.ldt = {0x00000000U, 0xC0000000U, 0x3FFFU + 0x0U, 1}}, -2}, /* -1.500000 */
+ {{.ldt = {0x085F4800U, 0xBFFFEF39U, 0x3FFFU + 0x0U, 0}}, +1}, /* 1.499998 */
+ {{.ldt = {0x085F4800U, 0xBFFFEF39U, 0x3FFFU + 0x0U, 1}}, -1}, /* -1.499998 */
+ {{.ldt = {0x00000000U, 0xB0000000U, 0x3FFFU + 0x0U, 0}}, +1}, /* 1.375000 */
+ {{.ldt = {0x00000000U, 0xB0000000U, 0x3FFFU + 0x0U, 1}}, -1}, /* -1.375000 */
+ {{.ldt = {0x00000000U, 0x90000000U, 0x3FFFU + 0x0U, 0}}, +1}, /* 1.125000 */
+ {{.ldt = {0x00000000U, 0x90000000U, 0x3FFFU + 0x0U, 1}}, -1}, /* -1.125000 */
+
+ {{.ldt = {0x00000000U, 0x80000000U, 0x3FFFU + 0x0016U, 0}}, +4194304}, /* 4194304.000000 */
+ {{.ldt = {0x00000000U, 0x80000000U, 0x3FFFU + 0x0016U, 1}}, -4194304}, /* -4194304.000000 */
+ {{.ldt = {0x00000000U, 0x80000000U, 0x3FFFU + 0x0017U, 0}}, +8388608}, /* 8388608.000000 */
+ {{.ldt = {0x00000000U, 0x80000000U, 0x3FFFU + 0x0017U, 1}}, -8388608}, /* -8388608.000000 */
+ {{.ldt = {0x00000000U, 0x80000000U, 0x3FFFU + 0x0018U, 0}}, +16777216}, /* 16777216.000000 */
+ {{.ldt = {0x00000000U, 0x80000000U, 0x3FFFU + 0x0018U, 1}}, -16777216}, /* -16777216.000000 */
+ {{.ldt = {0x00000000U, 0x80000000U, 0x3FFFU + 0x001EU, 0}}, +1073741824}, /* 1073741824.000000 */
+ {{.ldt = {0x00000000U, 0x80000000U, 0x3FFFU + 0x001EU, 1}}, -1073741824}, /* -1073741824.000000 */
+ {{.ldt = {0x00000000U, 0xFFFFFFFEU, 0x3FFFU + 0x001EU, 0}}, +2147483647LL}, /* 2147483647.000000 */
+ {{.ldt = {0x00000000U, 0x80000000U, 0x3FFFU + 0x001FU, 1}}, -2147483648LL}, /* -2147483648.000000 */
+ {{.ldt = {0x00000000U, 0x80000000U, 0x3FFFU + 0x0020U, 0}}, -2147483648LL}, /* 4294967296.000000 */
+ {{.ldt = {0x00000000U, 0x80000000U, 0x3FFFU + 0x0020U, 1}}, -2147483648LL}, /* -4294967296.000000 */
+
+ /* Number greater than 2**31 exceeds long int size and will be casted in an implementation defined manner. */
+ {{.ldt = {0x00000000U, 0x80000000U, 0x3FFFU + 0x001FU, 0}}, -2147483648LL}, /* 2147483648.0000000000 */
+ {{.ldt = {0x00000000U, 0x80000000U, 0x3FFFU + 0x001FU, 1}}, -2147483648LL}, /* -2147483648.0000000000 */
+
+ /* Number less than 0.5 will be truncated to 0. */
+ {{.ldt = {0xC42F9800U, 0xFFBC98FFU, 0x3FFFU + 0xFFFFFFFEU, 0}}, 0}, /* 0.4994857609 */
+ {{.ldt = {0xC42F9800U, 0xFFBC98FFU, 0x3FFFU + 0xFFFFFFFEU, 1}}, -0}, /* -0.4994857609 */
+ {{.ldt = {0x8D4FE000U, 0x83126E97U, 0x3FFFU + 0xFFFFFFF6U, 0}}, 0}, /* 0.0010000000 */
+ {{.ldt = {0x8D4FE000U, 0x83126E97U, 0x3FFFU + 0xFFFFFFF6U, 1}}, -0}, /* -0.0010000000 */
+
+ /* Number greater than 0.5 and less than 1 will be rounded to 1. */
+ {{.ldt = {0xC37A4000U, 0xFCD6E47DU, 0x3FFFU + 0xFFFFFFFFU, 0}}, 1}, /* 0.9876540000 */
+ {{.ldt = {0xC37A4000U, 0xFCD6E47DU, 0x3FFFU + 0xFFFFFFFFU, 1}}, -1}, /* -0.9876540000 */
+ {{.ldt = {0xB2B29800U, 0x80000101U, 0x3FFFU + 0xFFFFFFFFU, 0}}, 1}, /* 0.5000000600 */
+ {{.ldt = {0xB2B29800U, 0x80000101U, 0x3FFFU + 0xFFFFFFFFU, 1}}, -1}, /* -0.5000000600 */
+ {{.ldt = {0x00000000U, 0x80000000U, 0x3FFFU + 0xFFFFFFFFU, 0}}, 1}, /* 0.5000000000 */
+ {{.ldt = {0x00000000U, 0x80000000U, 0x3FFFU + 0xFFFFFFFFU, 1}}, -1}, /* -0.5000000000 */
+
+ /* Number greather than 1 and less than 2**31 will be rounded accordingly. */
+ {{.ldt = {0x00000000U, 0x80000000U, 0x3FFFU + 0x0000U, 0}}, 1}, /* 1.0000000000 */
+ {{.ldt = {0x00000000U, 0x80000000U, 0x3FFFU + 0x0000U, 1}}, -1}, /* -1.0000000000 */
+ {{.ldt = {0xF7A0B800U, 0x800010C6U, 0x3FFFU + 0x0000U, 0}}, 1}, /* 1.0000020000 */
+ {{.ldt = {0xF7A0B800U, 0x800010C6U, 0x3FFFU + 0x0000U, 1}}, -1}, /* -1.0000020000 */
+ {{.ldt = {0x00000000U, 0x80001800U, 0x3FFFU + 0x0010U, 0}}, 65536}, /* 65536.1875000000 */
+ {{.ldt = {0x00000000U, 0x80001800U, 0x3FFFU + 0x0010U, 1}}, -65536}, /* -65536.1875000000 */
+ {{.ldt = {0x00000000U, 0x80004000U, 0x3FFFU + 0x0010U, 0}}, 65537}, /* 65536.5000000000 */
+ {{.ldt = {0x00000000U, 0x80004000U, 0x3FFFU + 0x0010U, 1}}, -65537}, /* -65536.5000000000 */
+ {{.ldt = {0x00000000U, 0x80004D00U, 0x3FFFU + 0x0010U, 0}}, 65537}, /* 65536.6015625000 */
+ {{.ldt = {0x00000000U, 0x80004D00U, 0x3FFFU + 0x0010U, 1}}, -65537}, /* -65536.6015625000 */
+ {{.ldt = {0x00000000U, 0xFFFFFF00U, 0x3FFFU + 0x0016U, 0}}, 8388608}, /* 8388607.5000000000 */
+ {{.ldt = {0x00000000U, 0xFFFFFF00U, 0x3FFFU + 0x0016U, 1}}, -8388608}, /* -8388607.5000000000 */
+ {{.ldt = {0x00000000U, 0x80000500U, 0x3FFFU + 0x0014U, 0}}, 1048577}, /* 1048576.6250000000 */
+ {{.ldt = {0x00000000U, 0x80000500U, 0x3FFFU + 0x0014U, 1}}, -1048577}, /* -1048576.6250000000 */
+ {{.ldt = {0x00000000U, 0xFFFFFFFEU, 0x3FFFU + 0x001EU, 0}}, 2147483647}, /* 2147483647.0000000000 */
+ {{.ldt = {0x00000000U, 0xFFFFFFFEU, 0x3FFFU + 0x001EU, 1}}, -2147483647}, /* -2147483647.0000000000 */
+};
+
+static const size_t n_tests_long_double = sizeof(tests_long_double) / sizeof(tests_long_double[0]);
+
+
+int main(void)
+{
+ unsigned int i, counter;
+
+ for (counter = i = 0; i < n_tests_long_double; i++)
+ {
+ long int result = lroundl(tests_long_double[i].value.ld);
+
+ if (tests_long_double[i].should_be == result)
+ counter++;
+ else
+ printf("lroundl test failed: value to round = %.12Lf result = %ld should be = %ld\n", tests_long_double[i].value.ld, result, tests_long_double[i].should_be);
+ }
+ printf("%s\n", (counter < n_tests_long_double) ? "lroundl test failed." : "lroundl test succeded.");
+
+ return 0;
+}
- Raw text -