www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2013/09/18/18:25:52

X-Authentication-Warning: delorie.com: mail set sender to djgpp-workers-bounces using -f
X-Recipient: djgpp-workers AT delorie DOT com
Message-ID: <523A2796.8040908@gmx.de>
Date: Thu, 19 Sep 2013 00:22:14 +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]lrint[f|l] family of functions.
X-Provags-ID: V03:K0:N84f0S8qMKDzDbhH53HnzTIlw/iouNm4w2ZbZnwl9wILP3BhwTk
cFdgq282+GVZuzzJfZk0AKnjw6l95bGFscy6pAv//y6BpTzK6ckCh7bi1W6bxJCxGBakhjk
wsV/jS0WTCR5fNjDbfqqtro3LWFHYQ59m89pqFWUBTnb2vZ9H2GzReT+mXyFLT3mC9AuQ8D
N7MwSDinE0rgak1B25NCA==
Reply-To: djgpp-workers AT delorie DOT com

Below is a patch that shall provide the implementation of the [l]lrint[f|l]
family of functions in libm.a.  Some test cases have been added.  I have
compiled and tested the code with gcc473 and the djcross-gcc481.
As usual suggestions, objections and comments are welcome.

Regards,
Juan M. Guerrero



2013-09-12  Juan Manuel Guerrero  <juan DOT guerrero AT gmx DOT de>


     * djgpp/include/math.h: Prototypes of llrintl function added.

     * djgpp/include/libm/math.h: Prototypes of llrintl function added.

     * djgpp/src/libm/math/llrintl.c: Implementation of llrintl.

     * djgpp/src/libm/math/makefile: llrintl function added to goal list.

     * djgpp/src/libm/math/math.texi: Entry of llrintl function added.

     * djgpp/tests/cygnus/t-llrintl.c: Check for llrintl.

     * djgpp/tests/cygnus/makefile: llrintl function added to goal list.

     * djgpp/src/docs/kb/wc204.txi: Info about [l]lrint[f|l] family of
     functions added.


2013-09-11  Juan Manuel Guerrero  <juan DOT guerrero AT gmx DOT de>


     * djgpp/include/math.h: Prototypes of lrintl function added.

     * djgpp/include/libm/math.h: Prototypes of lrintl functions added.

     * djgpp/src/libm/math/lrintl.c: Implementation of lrintl.

     * djgpp/src/libm/math/makefile: lrintl functions added to goal list.

     * djgpp/src/libm/math/math.texi: Entry of lrintl function added.

     * djgpp/tests/cygnus/t-lrintl.c: Check for lrintl.

     * djgpp/tests/cygnus/makefile: lrintl function added to goal list.


2013-09-07  Juan Manuel Guerrero  <juan DOT guerrero AT gmx DOT de>


     * djgpp/include/math.h: Prototypes of [l]lrint functions added.

     * djgpp/include/libm/math.h: Prototypes of [l]lrint functions added.

     * djgpp/src/libm/math/llrint.c: Implementation of llrint.

     * djgpp/src/libm/math/lrint.c: Implementation of lrint.

     * djgpp/src/libm/math/makefile: [l]lrint functions added to goal list.

     * djgpp/src/libm/math/math.texi: Entries of [l]lrint functions added.

     * djgpp/tests/cygnus/t-lrint.c: Check for lrint.

     * djgpp/tests/cygnus/makefile: lrint function added to goal list.


2013-09-05  Juan Manuel Guerrero  <juan DOT guerrero AT gmx DOT de>


     * djgpp/include/math.h: Prototypes of [l]lrintf functions added.

     * djgpp/include/libm/math.h: Prototypes of [l]lrintf functions added.

     * djgpp/src/libm/math/lrintf.c: Implementation of lrintf.

     * djgpp/src/libm/math/llrintf.c: Implementation of llrintf.

     * djgpp/src/libm/math/makefile: [l]lrintf functions added to goal list.

     * djgpp/src/libm/math/math.texi: Entries of [l]lrintf of functions
     added.

     * djgpp/tests/cygnus/t-lrintf.c: Check for lrintf.

     * djgpp/tests/cygnus/makefile: lrintf functions added to goal list.






diff -aprNU5 djgpp.orig/include/libm/math.h djgpp/include/libm/math.h
--- djgpp.orig/include/libm/math.h    2013-03-05 19:06:46 +0100
+++ djgpp/include/libm/math.h    2013-09-18 22:34:36 +0100
@@ -159,10 +159,16 @@ extern double fmod __P((double, double))

  /* ISO C99 types and macros. */
  extern float truncf __P((float));
  extern double trunc __P((double));
  extern long double truncl __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 llrintf __P((float));
+extern long long int llrint __P((double));
+extern long long int llrintl __P((long double));
  #endif /* !defined (__STRICT_ANSI__) || defined(__cplusplus)
            || defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L */

  #if !defined(__STRICT_ANSI__) && !defined(_POSIX_SOURCE)
  extern double erf __P((double));
diff -aprNU5 djgpp.orig/include/math.h djgpp/include/math.h
--- djgpp.orig/include/math.h    2013-03-23 11:54:54 +0100
+++ djgpp/include/math.h    2013-09-18 22:34:36 +0100
@@ -189,10 +189,14 @@ extern double copysign(double, double);
  extern int ilogb(double);
  extern double rint(double);
  extern double scalbn(double, int);
  extern double trunc(double);
  extern long double truncl(long double);
+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 float erff(float);
  extern float erfcf(float);
  extern float hypotf(float, float);
  extern float lgammaf(float);
  extern float acoshf(float);
@@ -208,10 +212,12 @@ extern int ilogbf(float);
  extern float rintf(float);
  extern float scalbnf(float, int);
  extern float expm1f(float);
  extern float log1pf(float);
  extern float truncf(float);
+extern long int lrintf(float);
+extern long long int llrintf(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-09-12 21:24:52 +0100
+++ djgpp/src/docs/kb/wc204.txi    2013-09-18 22:34:36 +0100
@@ -1308,5 +1308,15 @@ were added to comply with the @acronym{C
  @findex fputs AT r{, and stream error condition}
  Openning a file stream in the wrong mode referring to the following
  input/output operation (e.g.: openning stream in read only mode and
  then writing to it), will trigger a stream error condition that will
  set an error indicator.  This error indicator can be tested using @code{ferror}.
+
+@cindex @acronym{C99} compliance, @code{math.h}
+@findex lrintf AT r{ added}
+@findex lrint AT r{ added}
+@findex lrintl AT r{ added}
+@findex llrintf AT r{ added}
+@findex llrint AT r{ added}
+@findex llrintl AT r{ added}
+The @acronym{C99} functions @code{lrintf}, @code{lrint}, @code{lrintl}, @code{llrintf},
+@code{llrint} and @code{llrintl} were added to comply with the @acronym{C99} standard.
diff -aprNU5 djgpp.orig/src/libm/math/llrint.c djgpp/src/libm/math/llrint.c
--- djgpp.orig/src/libm/math/llrint.c    1970-01-01 01:00:00 +0100
+++ djgpp/src/libm/math/llrint.c    2013-09-18 22:34:36 +0100
@@ -0,0 +1,116 @@
+/* Copyright (C) 2013 DJ Delorie, see COPYING.DJ for details */
+
+/*
+FUNCTION
+<<llrint>>, <<llrintf>>, <<llrintl>>--round to nearest integer value using current rounding direction
+INDEX
+    llrint
+INDEX
+    llrintf
+INDEX
+    llrint
+
+ANSI_SYNOPSIS
+        #include <math.h>
+        long long int llrint(double <[x]>);
+        long long int llrintf(float <[x]>);
+        long long int llrintl(long double <[x]>);
+
+DESCRIPTION
+The <<llrint>> functions round their argument to the nearest integer value,
+using the current rounding direction.
+
+Note that unlike <<rint>>, etc., the return type of these functions differs
+from that of their arguments.
+
+RETURNS
+These functions return the rounded integer value of <[x]>.
+If <[x]> is NaN or an infinity, or the rounded value is too large
+to be stored in a long then a domain error occurs, and the return
+value is unspecified.
+
+These functions do not set errno.
+
+PORTABILITY
+ANSI C, POSIX
+
+*/
+
+#include <stdint.h>
+#include <math.h>
+#include <libc/ieee.h>
+
+#define DOUBLE_BIAS                             (0x3FFU)
+#define BIN_DIGITS_IN_FRACTION                  (52)  /*  Amount of binary digits in fraction part of mantissa.  */
+#define BIN_DIGITS_IN_MSW                       (20)  /*  Amount of binary digits in msw of the fraction part of mantissa.  */
+#define MAGNITUDE_IS_TOO_LARGE(x)               ((x) > (int)(sizeof(long long int) * 8) - 2)
+#define MSW_TO_INTEGER(x, unbiased_exponent)    ((long long int)(((uint64_t)(x).dt.mantissah | 0x100000) >> (BIN_DIGITS_IN_MSW - (unbiased_exponent))))
+#define SHIFT_LEFT_MSW(x, unbiased_exponent) (((uint64_t)(x).dt.mantissah | 0x100000) << ((unbiased_exponent) - BIN_DIGITS_IN_MSW))
+#define ROUND_TO_INTEGER(x, unbiased_exponent)  ((long long int)(SHIFT_LEFT_MSW(x, unbiased_exponent) | (x).dt.mantissal >> (BIN_DIGITS_IN_FRACTION - (unbiased_exponent))))
+#define TO_INTEGER(x, unbiased_exponent)        ((long long int)(SHIFT_LEFT_MSW(x, unbiased_exponent) | (x).dt.mantissal << ((unbiased_exponent) - BIN_DIGITS_IN_FRACTION)))
+#define IS_ZERO(x)                              ((((x).dt.mantissah & ~(1L << BIN_DIGITS_IN_MSW)) == 0) && (((x).dt.mantissal & 0xFFFFFFFFU) == 0) && (((x).dt.exponent & 0x7FFU) == 0))
+
+
+/* Adding a double, x, to 2^52 will cause the result to be rounded based on
+   the fractional part of x, according to the implementation's current rounding
+   mode.  2^52 is the smallest double that can be represented using all 52 significant
+   digits. */
+#ifdef __STDC__
+static const double
+#else
+static double
+#endif
+two52[2] = {
+  4503599627370496, /* 0, 0x3FFU + 0x034U, 0x00000U, 0x00000000U */
+ -4503599627370496, /* 1, 0x3FFU + 0x034U, 0x00000U, 0x00000000U */
+};
+
+#ifdef __STDC__
+long long int
+llrint(double x)
+#else
+long long int
+llrint(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 (unbiased_exponent < BIN_DIGITS_IN_MSW)
+  {
+    if (unbiased_exponent < -1)
+      return 0;
+    else
+    {
+      ieee_value.d = two52[sign] + x;
+      ieee_value.d -= two52[sign];
+      unbiased_exponent = ieee_value.dt.exponent - DOUBLE_BIAS;
+
+      result = (unbiased_exponent < 0) || IS_ZERO(ieee_value) ? 0 : MSW_TO_INTEGER(ieee_value, unbiased_exponent);
+    }
+  }
+  else
+  {
+    if (unbiased_exponent > (BIN_DIGITS_IN_FRACTION - 1))
+      result = TO_INTEGER(ieee_value, unbiased_exponent);  /* >= 2^52 is already an exact integer.  */
+    else
+    {
+      ieee_value.d = two52[sign] + x;
+      ieee_value.d -= two52[sign];
+      unbiased_exponent = ieee_value.dt.exponent - DOUBLE_BIAS;
+
+      result = (unbiased_exponent == BIN_DIGITS_IN_MSW) ? (long long int)ieee_value.dt.mantissah : ROUND_TO_INTEGER(ieee_value, unbiased_exponent);
+    }
+  }
+
+  return sign ? -result : result;
+}
diff -aprNU5 djgpp.orig/src/libm/math/llrintf.c djgpp/src/libm/math/llrintf.c
--- djgpp.orig/src/libm/math/llrintf.c    1970-01-01 01:00:00 +0100
+++ djgpp/src/libm/math/llrintf.c    2013-09-18 22:34:36 +0100
@@ -0,0 +1,60 @@
+/* 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(x)               ((x) > (int)(sizeof(long long int) * 8) - 2)
+#define TO_INTEGER(x, unbiased_exponent)        ((long int)((uint32_t)(x).ft.mantissa | 0x800000) << ((unbiased_exponent) - BIN_DIGITS_IN_FRACTION))
+#define ROUND_TO_INTEGER(x, unbiased_exponent)  ((long int)((uint32_t)(x).ft.mantissa | 0x800000) >> (BIN_DIGITS_IN_FRACTION - (unbiased_exponent)))
+#define IS_ZERO(x)                              ((((x).ft.mantissa & ~(1L << BIN_DIGITS_IN_FRACTION)) == 0) && (((x).ft.exponent & 0xFFU) == 0))
+
+
+/* Adding a float, x, to 2^23 will cause the result to be rounded based on
+   the fractional part of x, according to the implementation's current rounding
+   mode.  2^23 is the smallest float that can be represented using all 23 significant
+   digits. */
+#ifdef __STDC__
+static const float
+#else
+static float
+#endif
+two23[2] = {
+  8388608,  /* 0, 0x7FU + 0x17U, 0x000000U */
+ -8388608,  /* 1, 0x7FU + 0x17U, 0x000000U */
+};
+
+long long int
+llrintf(float x)
+{
+  _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 (unbiased_exponent < -1)
+      return 0;
+    else if (unbiased_exponent > (BIN_DIGITS_IN_FRACTION - 1))
+      result = TO_INTEGER(ieee_value, unbiased_exponent);  /* >= 2^23 is already an exact integer.  */
+    else
+    {
+      ieee_value.f = two23[sign] + x;
+      ieee_value.f -= two23[sign];
+      unbiased_exponent = ieee_value.ft.exponent - FLOAT_BIAS;
+
+      result = (unbiased_exponent < 0) || IS_ZERO(ieee_value) ? 0 : ROUND_TO_INTEGER(ieee_value, unbiased_exponent);
+    }
+  }
+
+  return sign ? -result : result;
+}
diff -aprNU5 djgpp.orig/src/libm/math/llrintl.c djgpp/src/libm/math/llrintl.c
--- djgpp.orig/src/libm/math/llrintl.c    1970-01-01 01:00:00 +0100
+++ djgpp/src/libm/math/llrintl.c    2013-09-18 22:34:36 +0100
@@ -0,0 +1,80 @@
+/* Copyright (C) 2013 DJ Delorie, see COPYING.DJ for details */
+
+#include <stdint.h>
+#include <math.h>
+#include <libc/ieee.h>
+
+#define LONG_DOUBLE_BIAS                        (0x3FFFU)
+#define BIN_DIGITS_IN_FRACTION                  (63)  /*  Amount of binary digits in fraction part of mantissa.  */
+#define BIN_DIGITS_IN_MSW                       (31)  /*  Amount of binary digits in msw of the fraction part of mantissa.  */
+#define MAGNITUDE_IS_TOO_LARGE(x)               ((x) > (int)(sizeof(long long int) * 8) - 2)
+#define MSW_TO_INTEGER(x, unbiased_exponent) (((uint64_t)(x).ldt.mantissah) >> (BIN_DIGITS_IN_MSW - (unbiased_exponent)))
+#define SHIFT_LEFT_MSW(x, unbiased_exponent) (((uint64_t)(x).ldt.mantissah) << ((unbiased_exponent) - BIN_DIGITS_IN_MSW))
+#define ROUND_TO_INTEGER(x, unbiased_exponent)  ((long long int)(SHIFT_LEFT_MSW(x, unbiased_exponent) | (x).ldt.mantissal >> (BIN_DIGITS_IN_FRACTION - (unbiased_exponent))))
+#define TO_INTEGER(x, unbiased_exponent)        ((long long int)(SHIFT_LEFT_MSW(x, unbiased_exponent) | (x).ldt.mantissal << ((unbiased_exponent) - BIN_DIGITS_IN_FRACTION)))
+#define IS_ZERO(x) ((((x).ldt.mantissah & 0xFFFFFFFFU) == 0) && (((x).ldt.mantissal & 0xFFFFFFFFU) == 0) && (((x).ldt.exponent & 0x7FFFU) == 0))
+
+
+/* Adding a long double, x, to 2^63 will cause the result to be rounded based on
+   the fractional part of x, according to the implementation's current rounding
+   mode.  2^63 is the smallest long double that can be represented using all 63
+   significant digits. */
+#ifdef __STDC__
+static const long double
+#else
+static long double
+#endif
+two63[2] = {
+  9.223372036854775808E+18,  /* 0, 0x3FFFE + 0x003F, 0x80000000U, 0x00000000U */
+ -9.223372036854775808E+18,  /* 1, 0x3FFFE + 0x003F, 0x80000000U, 0x00000000U */
+};
+
+#ifdef __STDC__
+long long int
+llrintl(long double x)
+#else
+long long int
+llrintl(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 (unbiased_exponent < BIN_DIGITS_IN_MSW)
+  {
+    if (unbiased_exponent < -1)
+      return 0;
+    else
+    {
+      ieee_value.ld = two63[sign] + x;
+      ieee_value.ld -= two63[sign];
+      unbiased_exponent = ieee_value.ldt.exponent - LONG_DOUBLE_BIAS;
+
+      result = (unbiased_exponent < 0) || IS_ZERO(ieee_value) ? 0 : MSW_TO_INTEGER(ieee_value, unbiased_exponent);
+    }
+  }
+  else
+  {
+    if (unbiased_exponent > (BIN_DIGITS_IN_FRACTION - 1))
+      result = TO_INTEGER(ieee_value, unbiased_exponent);
+    else
+    {
+      ieee_value.ld = two63[sign] + x;
+      ieee_value.ld -= two63[sign];
+      unbiased_exponent = ieee_value.ldt.exponent - LONG_DOUBLE_BIAS;
+
+      result = (unbiased_exponent == BIN_DIGITS_IN_MSW) ? (long long int)ieee_value.ldt.mantissah : ROUND_TO_INTEGER(ieee_value, unbiased_exponent);
+    }
+  }
+
+  return sign ? -result : result;
+}
diff -aprNU5 djgpp.orig/src/libm/math/lrint.c djgpp/src/libm/math/lrint.c
--- djgpp.orig/src/libm/math/lrint.c    1970-01-01 01:00:00 +0100
+++ djgpp/src/libm/math/lrint.c    2013-09-18 22:34:36 +0100
@@ -0,0 +1,116 @@
+/* Copyright (C) 2013 DJ Delorie, see COPYING.DJ for details */
+
+/*
+FUNCTION
+<<lrint>>, <<lrintf>>, <<lrintl>>--round to nearest integer value using current rounding direction
+INDEX
+    lrint
+INDEX
+    lrintf
+INDEX
+    lrint
+
+ANSI_SYNOPSIS
+        #include <math.h>
+        long int lrint(double <[x]>);
+        long int lrintf(float <[x]>);
+        long int lrintl(long double <[x]>);
+
+DESCRIPTION
+The <<lrint>> functions round their argument to the nearest integer value,
+using the current rounding direction.
+
+Note that unlike <<rint>>, etc., the return type of these functions differs
+from that of their arguments.
+
+RETURNS
+These functions return the rounded integer value of <[x]>.
+If <[x]> is NaN or an infinity, or the rounded value is too large
+to be stored in a long then a domain error occurs, and the return
+value is unspecified.
+
+These functions do not set errno.
+
+PORTABILITY
+ANSI C, POSIX
+
+*/
+
+#include <stdint.h>
+#include <math.h>
+#include <libc/ieee.h>
+
+#define DOUBLE_BIAS                             (0x3FFU)
+#define BIN_DIGITS_IN_FRACTION                  (52)  /*  Amount of binary digits in fraction part of mantissa.  */
+#define BIN_DIGITS_IN_MSW                       (20)  /*  Amount of binary digits in msw of the fraction part of mantissa.  */
+#define MAGNITUDE_IS_TOO_LARGE(x)               ((x) > (int)(sizeof(long int) * 8) - 2)
+#define MSW_TO_INTEGER(x, unbiased_exponent) (((uint32_t)(x).dt.mantissah | 0x100000) >> (BIN_DIGITS_IN_MSW - (unbiased_exponent)))
+#define SHIFT_LEFT_MSW(x, unbiased_exponent) (((uint32_t)(x).dt.mantissah | 0x100000) << ((unbiased_exponent) - BIN_DIGITS_IN_MSW))
+#define ROUND_TO_INTEGER(x, unbiased_exponent)  ((long int)(SHIFT_LEFT_MSW(x, unbiased_exponent) | (x).dt.mantissal >> (BIN_DIGITS_IN_FRACTION - (unbiased_exponent))))
+#define TO_INTEGER(x, unbiased_exponent)        ((long int)(SHIFT_LEFT_MSW(x, unbiased_exponent) | (x).dt.mantissal << ((unbiased_exponent) - BIN_DIGITS_IN_FRACTION)))
+#define IS_ZERO(x)                              ((((x).dt.mantissah & ~(1L << BIN_DIGITS_IN_MSW)) == 0) && (((x).dt.mantissal & 0xFFFFFFFFU) == 0) && (((x).dt.exponent & 0x7FFU) == 0))
+
+
+/* Adding a double, x, to 2^52 will cause the result to be rounded based on
+   the fractional part of x, according to the implementation's current rounding
+   mode.  2^52 is the smallest double that can be represented using all 52 significant
+   digits. */
+#ifdef __STDC__
+static const double
+#else
+static double
+#endif
+two52[2] = {
+  4503599627370496, /* 0, 0x3FFU + 0x034U, 0x00000U, 0x00000000U */
+ -4503599627370496, /* 1, 0x3FFU + 0x034U, 0x00000U, 0x00000000U */
+};
+
+#ifdef __STDC__
+long int
+lrint(double x)
+#else
+long int
+lrint(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 (unbiased_exponent < BIN_DIGITS_IN_MSW)
+  {
+    if (unbiased_exponent < -1)
+      return 0;
+    else
+    {
+      ieee_value.d = two52[sign] + x;
+      ieee_value.d -= two52[sign];
+      unbiased_exponent = ieee_value.dt.exponent - DOUBLE_BIAS;
+
+      result = (unbiased_exponent < 0) || IS_ZERO(ieee_value) ? 0 : MSW_TO_INTEGER(ieee_value, unbiased_exponent);
+    }
+  }
+  else
+  {
+    if (unbiased_exponent > (BIN_DIGITS_IN_FRACTION - 1))  /* >= 2^52 is already an exact integer iff long int is 64 bit.  */
+      result = TO_INTEGER(ieee_value, unbiased_exponent);  /* But this is not the case with djgpp.  */
+    else
+    {
+      ieee_value.d = two52[sign] + x;
+      ieee_value.d -= two52[sign];
+      unbiased_exponent = ieee_value.dt.exponent - DOUBLE_BIAS;
+
+      result = (unbiased_exponent == BIN_DIGITS_IN_MSW) ? (long int)ieee_value.dt.mantissah : ROUND_TO_INTEGER(ieee_value, unbiased_exponent);
+    }
+  }
+
+  return sign ? -result : result;
+}
diff -aprNU5 djgpp.orig/src/libm/math/lrintf.c djgpp/src/libm/math/lrintf.c
--- djgpp.orig/src/libm/math/lrintf.c    1970-01-01 01:00:00 +0100
+++ djgpp/src/libm/math/lrintf.c    2013-09-18 22:34:36 +0100
@@ -0,0 +1,66 @@
+/* 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(x)               ((x) > (int)(sizeof(long int) * 8) - 2)
+#define TO_INTEGER(x, unbiased_exponent)        ((long int)((uint32_t)(x).ft.mantissa | 0x800000) << ((unbiased_exponent) - BIN_DIGITS_IN_FRACTION))
+#define ROUND_TO_INTEGER(x, unbiased_exponent)  ((long int)((uint32_t)(x).ft.mantissa | 0x800000) >> (BIN_DIGITS_IN_FRACTION - (unbiased_exponent)))
+#define IS_ZERO(x)                              ((((x).ft.mantissa & ~(1L << BIN_DIGITS_IN_FRACTION)) == 0) && (((x).ft.exponent & 0xFFU) == 0))
+
+
+/* Adding a float, x, to 2^23 will cause the result to be rounded based on
+   the fractional part of x, according to the implementation's current rounding
+   mode.  2^23 is the smallest float that can be represented using all 23 significant
+   digits. */
+#ifdef __STDC__
+static const float
+#else
+static float
+#endif
+two23[2] = {
+  8388608,  /* 0, 0x7FU + 0x17U, 0x000000U */
+ -8388608,  /* 1, 0x7FU + 0x17U, 0x000000U */
+};
+
+#ifdef __STDC__
+long int
+lrintf(float x)
+#else
+long int
+lrintf(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 (unbiased_exponent < -1)
+      return 0;
+    else if (unbiased_exponent > (BIN_DIGITS_IN_FRACTION - 1))
+      result = TO_INTEGER(ieee_value, unbiased_exponent);  /* >= 2^23 is already an exact integer.  */
+    else
+    {
+      ieee_value.f = two23[sign] + x;
+      ieee_value.f -= two23[sign];
+      unbiased_exponent = ieee_value.ft.exponent - FLOAT_BIAS;
+
+      result = (unbiased_exponent < 0) || IS_ZERO(ieee_value) ? 0 : ROUND_TO_INTEGER(ieee_value, unbiased_exponent);
+    }
+  }
+
+  return sign ? -result : result;
+}
diff -aprNU5 djgpp.orig/src/libm/math/lrintl.c djgpp/src/libm/math/lrintl.c
--- djgpp.orig/src/libm/math/lrintl.c    1970-01-01 01:00:00 +0100
+++ djgpp/src/libm/math/lrintl.c    2013-09-18 22:34:36 +0100
@@ -0,0 +1,80 @@
+/* Copyright (C) 2013 DJ Delorie, see COPYING.DJ for details */
+
+#include <stdint.h>
+#include <math.h>
+#include <libc/ieee.h>
+
+#define LONG_DOUBLE_BIAS                        (0x3FFFU)
+#define BIN_DIGITS_IN_FRACTION                  (63)  /*  Amount of binary digits in fraction part of mantissa.  */
+#define BIN_DIGITS_IN_MSW                       (31)  /*  Amount of binary digits in msw of the fraction part of mantissa.  */
+#define MAGNITUDE_IS_TOO_LARGE(x)               ((x) > (int)(sizeof(long int) * 8) - 2)
+#define MSW_TO_INTEGER(x, unbiased_exponent) (((uint32_t)(x).ldt.mantissah) >> (BIN_DIGITS_IN_MSW - (unbiased_exponent)))
+#define SHIFT_LEFT_MSW(x, unbiased_exponent) (((uint32_t)(x).ldt.mantissah) << ((unbiased_exponent) - BIN_DIGITS_IN_MSW))
+#define ROUND_TO_INTEGER(x, unbiased_exponent)  ((long int)(SHIFT_LEFT_MSW(x, unbiased_exponent) | (x).ldt.mantissal >> (BIN_DIGITS_IN_FRACTION - (unbiased_exponent))))
+#define TO_INTEGER(x, unbiased_exponent)        ((long int)(SHIFT_LEFT_MSW(x, unbiased_exponent) | (x).ldt.mantissal << ((unbiased_exponent) - BIN_DIGITS_IN_FRACTION)))
+#define IS_ZERO(x) ((((x).ldt.mantissah & 0xFFFFFFFFU) == 0) && (((x).ldt.mantissal & 0xFFFFFFFFU) == 0) && (((x).ldt.exponent & 0x7FFFU) == 0))
+
+
+/* Adding a long double, x, to 2^63 will cause the result to be rounded based on
+   the fractional part of x, according to the implementation's current rounding
+   mode.  2^63 is the smallest long double that can be represented using all 63
+   significant digits. */
+#ifdef __STDC__
+static const long double
+#else
+static long double
+#endif
+two63[2] = {
+  9.223372036854775808E+18,  /* 0, 0x3FFFE + 0x003F, 0x80000000U, 0x00000000U */
+ -9.223372036854775808E+18,  /* 1, 0x3FFFE + 0x003F, 0x80000000U, 0x00000000U */
+};
+
+#ifdef __STDC__
+long int
+lrintl(long double x)
+#else
+long int
+lrintl(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 (unbiased_exponent < BIN_DIGITS_IN_MSW)
+  {
+    if (unbiased_exponent < -1)
+      return 0;
+    else
+    {
+      ieee_value.ld = two63[sign] + x;
+      ieee_value.ld -= two63[sign];
+      unbiased_exponent = ieee_value.ldt.exponent - LONG_DOUBLE_BIAS;
+
+      result = (unbiased_exponent < 0) || IS_ZERO(ieee_value) ? 0 : MSW_TO_INTEGER(ieee_value, unbiased_exponent);
+    }
+  }
+  else
+  {
+    if (unbiased_exponent > (BIN_DIGITS_IN_FRACTION - 1))
+      result = TO_INTEGER(ieee_value, unbiased_exponent);  /* >= 2^63 is already an exact integer iff long int is 64 bit.  */
+    else
+    {
+      ieee_value.ld = two63[sign] + x;
+      ieee_value.ld -= two63[sign];
+      unbiased_exponent = ieee_value.ldt.exponent - LONG_DOUBLE_BIAS;
+
+      result = (unbiased_exponent == BIN_DIGITS_IN_MSW) ? (long int)ieee_value.ldt.mantissah : ROUND_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-03-05 19:18:14 +0100
+++ djgpp/src/libm/math/makefile    2013-09-18 22:34:36 +0100
@@ -162,24 +162,31 @@ SRC += sf_sin.c
  SRC += sf_tan.c
  SRC += sf_tanh.c
  SRC += sf_infinity.c
  SRC += sf_isinf.c
  SRC += sf_nan.c
-SRC += trunc
-SRC += truncf
-SRC += truncl
+SRC += trunc.c
+SRC += truncf.c
+SRC += truncl.c
+SRC += lrintf.c
+SRC += llrintf.c
+SRC += lrint.c
+SRC += llrint.c
+SRC += lrintl.c
+SRC += llrintl.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 \
      w_gamma.def w_hypot.def s_ldexp.def w_log.def \
      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
+    s_nan.def s_ilogb.def s_expm1.def trunc.def \
+    lrint.def llrint.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/src/libm/math/math.texi djgpp/src/libm/math/math.texi
--- djgpp.orig/src/libm/math/math.texi    2013-03-05 19:06:48 +0100
+++ djgpp/src/libm/math/math.texi    2013-09-18 22:34:36 +0100
@@ -54,10 +54,12 @@ available when you include @file{math.h}
  * isnan::    Check type of number
  * ldexp::    Load exponent
  * log::        Natural logarithms
  * log10::    Base 10 logarithms
  * log1p::    Log of 1 + X
+* lrint::    Round to integer
+* llrint::    Round to integer
  * matherr::    Modifiable math error handler
  * modf::    Split fractional and integer parts
  * nan::        Floating Not a Number
  * nextafter::    Get next representable number
  * pow::        X to the power Y
@@ -224,5 +226,12 @@ The library is set to X/Open mode by def
  @page
  @include s_tanh.def

  @page
  @include trunc.def
+
+@page
+@include lrint.def
+
+@page
+@include llrint.def
+
diff -aprNU5 djgpp.orig/tests/cygnus/makefile djgpp/tests/cygnus/makefile
--- djgpp.orig/tests/cygnus/makefile    2013-03-05 19:06:54 +0100
+++ djgpp/tests/cygnus/makefile    2013-09-18 22:34:36 +0100
@@ -92,15 +92,20 @@ 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
+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
      ./mtest.exe > mtest.results
-    ./t-trunc.exe
-    ./t-truncf.exe
-    ./t-truncl.exe
+    ./t-trunc.exe >> mtest.results
+    ./t-truncf.exe >> mtest.results
+    ./t-truncl.exe >> mtest.results
+    ./t-lrintf.exe >> mtest.results
+    ./t-lrint.exe >> mtest.results
+    ./t-lrintl.exe >> mtest.results
+    ./t-llrint.exe >> mtest.results
+    ./t-llrintl.exe >> mtest.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-
@@ -135,13 +140,28 @@ t-truncf.exe: t-truncf.o
      $(CC) -o $@ $(LDFLAGS) t-truncf.o $(LIBS)

  t-truncl.exe: t-truncl.o
      $(CC) -o $@ $(LDFLAGS) t-truncl.o $(LIBS)

+t-lrint.exe: t-lrint.o
+    $(CC) -o $@ $(LDFLAGS) t-lrint.o $(LIBS)
+
+t-lrintf.exe: t-lrintf.o
+    $(CC) -o $@ $(LDFLAGS) t-lrintf.o $(LIBS)
+
+t-lrintl.exe: t-lrintl.o
+    $(CC) -o $@ $(LDFLAGS) t-lrintl.o $(LIBS)
+
+t-llrint.exe: t-llrint.o
+    $(CC) -o $@ $(LDFLAGS) t-llrint.o $(LIBS)
+
+t-llrintl.exe: t-llrintl.o
+    $(CC) -o $@ $(LDFLAGS) t-llrintl.o $(LIBS)
+
  $(OFILES) $(VEC_OFILES) : test.h

  clean mostlyclean:
      -cd tgen; $(MAKE) $@
-    cd $(HERE); $(RM) $(OFILES) $(VEC_OFILES) *~ *.exe mtest.results t-trunc*.o
+    cd $(HERE); $(RM) $(OFILES) $(VEC_OFILES) *~ *.exe mtest.results t-trunc*.o t-lrint*.o t-llrint*.o

  .SECONDARY: $(GEN_PROGS) $(GEN_VEC_FILES)
  .PHONY: all check clean mostlyclean
diff -aprNU5 djgpp.orig/tests/cygnus/t-llrint.c djgpp/tests/cygnus/t-llrint.c
--- djgpp.orig/tests/cygnus/t-llrint.c    1970-01-01 01:00:00 +0100
+++ djgpp/tests/cygnus/t-llrint.c    2013-09-19 00:04:08 +0100
@@ -0,0 +1,104 @@
+/* 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 */
+};
+
+static const size_t n_tests_double = sizeof(tests_double) / sizeof(tests_double[0]);
+
+
+int main(void)
+{
+  int i, counter;
+
+  for (counter = i = 0; i < n_tests_double; i++)
+  {
+    long long int result = llrint(tests_double[i].value.d);
+
+    if (tests_double[i].should_be == result)
+      counter++;
+    else
+      printf("llrint 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) ? "llrint test failed." : "llrint test succeded.");
+
+  return 0;
+}
diff -aprNU5 djgpp.orig/tests/cygnus/t-llrintl.c djgpp/tests/cygnus/t-llrintl.c
--- djgpp.orig/tests/cygnus/t-llrintl.c    1970-01-01 01:00:00 +0100
+++ djgpp/tests/cygnus/t-llrintl.c    2013-09-18 22:51:42 +0100
@@ -0,0 +1,125 @@
+/* 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.223372036854775808E18}, /* Big number. */
+  {{.ldt = {0xFFFFFFFFU, 0xFFFFFFFFU, 0x7FFEU, 1}}, -9.223372036854775808E18}, /* Big -number. */
+
+  /* Infs. */
+  {{.ldt = {0x0U, 0x80000000U, 0x7FFFU, 0}}, -9.223372036854775808E18}, /* Inf */
+  {{.ldt = {0x0U, 0x80000000U, 0x7FFFU, 1}}, -9.223372036854775808E18}, /* -Inf */
+
+  /* NaNs. */
+  {{.ldt = {0x1U, 0x80000000U, 0x7FFFU, 0}}, -9.223372036854775808E18}, /* SNaN */
+  {{.ldt = {0x1U, 0x80000000U, 0x7FFFU, 1}}, -9.223372036854775808E18}, /* -SNaN */
+  {{.ldt = {0x0U, 0xFFFFFFFFU, 0x7FFFU, 0}}, -9.223372036854775808E18}, /* QNaN */
+  {{.ldt = {0x0U, 0xFFFFFFFFU, 0x7FFFU, 1}}, -9.223372036854775808E18}, /* -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 */
+
+  {{.ldt = {0x89A00000U, 0x81234567U, 0x3FFFU + 0x0033U, 0}}, 2271815812028928}, /* 2271815812028928.000000 */
+  {{.ldt = {0x89A00000U, 0x81234567U, 0x3FFFU + 0x0033U, 1}}, -2271815812028928}, /* -2271815812028928.000000 */
+  {{.ldt = {0xC4D58000U, 0x8091A2B3U, 0x3FFFU + 0x0034U, 0}}, 4523615625714352}, /* 4523615625714352.000000 */
+  {{.ldt = {0xC4D58000U, 0x8091A2B3U, 0x3FFFU + 0x0034U, 1}}, -4523615625714352}, /* -4523615625714352.000000 */
+  {{.ldt = {0x3B2A1800U, 0xFF6E5D4CU, 0x3FFFU + 0x0034U, 0}}, 8987183256397123}, /* 8987183256397123.000000 */
+  {{.ldt = {0x3B2A1800U, 0xFF6E5D4CU, 0x3FFFU + 0x0034U, 1}}, -8987183256397123}, /* -8987183256397123.000000 */
+  {{.ldt = {0x00000000U, 0x80000000U, 0x3FFFU + 0x0035U, 0}}, 9007199254740992}, /* 9007199254740992.000000 */
+  {{.ldt = {0x00000000U, 0x80000000U, 0x3FFFU + 0x0035U, 1}}, -9007199254740992}, /* -9007199254740992.000000 */
+  {{.ldt = {0x4D5E7000U, 0x891A2B3CU, 0x3FFFU + 0x0035U, 0}}, 9647711201744796}, /* 9647711201744796.000000 */
+  {{.ldt = {0x4D5E7000U, 0x891A2B3CU, 0x3FFFU + 0x0035U, 1}}, -9647711201744796}, /* -9647711201744796.000000 */
+  {{.ldt = {0x76543000U, 0xFEDCBA98U, 0x3FFFU + 0x0041U, 0}}, -9.223372036854775808E18}, /* 73459034177972256768.000000 */
+  {{.ldt = {0x76543000U, 0xFEDCBA98U, 0x3FFFU + 0x0041U, 1}}, -9.223372036854775808E18}, /* -73459034177972256768.000000 */
+  {{.ldt = {0x00000000U, 0x80000000U, 0x3FFFU + 0x003FU, 0}}, -9.223372036854775808E18}, /* 9223372036854775808.000000 */
+  {{.ldt = {0x00000000U, 0x80000000U, 0x3FFFU + 0x003FU, 1}}, -9.223372036854775808E18}, /* -9223372036854775808.000000 */
+  {{.ldt = {0x00000000U, 0xC0000000U, 0x3FFFU + 0x003FU, 0}}, -9.223372036854775808E18}, /* 13835058055282163712.000000 */
+  {{.ldt = {0x00000000U, 0xC0000000U, 0x3FFFU + 0x003FU, 1}}, -9.223372036854775808E18}, /* -13835058055282163712.000000 */
+  {{.ldt = {0x00000000U, 0xF0000000U, 0x3FFFU + 0x0042U, 0}}, -9.223372036854775808E18}, /* 138350580552821637120.000000 */
+  {{.ldt = {0x00000000U, 0xF0000000U, 0x3FFFU + 0x0042U, 1}}, -9.223372036854775808E18}, /* -138350580552821637120.000000 */
+  {{.ldt = {0xBA987800U, 0xF7FFFEDCU, 0x3FFFU + 0x0042U, 0}}, -9.223372036854775808E18}, /* 142962256563249856512.000000 */
+  {{.ldt = {0xBA987800U, 0xF7FFFEDCU, 0x3FFFU + 0x0042U, 1}}, -9.223372036854775808E18}, /* -142962256563249856512.000000 */
+  {{.ldt = {0x00000000U, 0xF8000000U, 0x3FFFU + 0x0042U, 0}}, -9.223372036854775808E18}, /* 142962266571249025024.000000 */
+  {{.ldt = {0x00000000U, 0xF8000000U, 0x3FFFU + 0x0042U, 1}}, -9.223372036854775808E18}, /* -142962266571249025024.000000 */
+  {{.ldt = {0x00012000U, 0xF8000000U, 0x3FFFU + 0x0042U, 0}}, -9.223372036854775808E18}, /* 142962266571249614848.000000 */
+  {{.ldt = {0x00012000U, 0xF8000000U, 0x3FFFU + 0x0042U, 1}}, -9.223372036854775808E18}, /* -142962266571249614848.000000 */
+  {{.ldt = {0x76543000U, 0xFEDCBA98U, 0x3FFFU + 0x0042U, 0}}, -9.223372036854775808E18}, /* 146918068355944513536.000000 */
+  {{.ldt = {0x76543000U, 0xFEDCBA98U, 0x3FFFU + 0x0042U, 1}}, -9.223372036854775808E18}, /* 147573952589676396544.000000 */
+  {{.ldt = {0xFFFFF800U, 0xFFFFFFFFU, 0x3FFFU + 0x0042U, 0}}, -9.223372036854775808E18}, /* -147573952589676396544.000000 */
+  {{.ldt = {0xFFFFF800U, 0xFFFFFFFFU, 0x3FFFU + 0x0042U, 1}}, -9.223372036854775808E18}, /* -147573952589676396544.000000 */
+  {{.ldt = {0x00000000U, 0x80000000U, 0x3FFFU + 0x0040U, 0}}, -9.223372036854775808E18}, /* 18446744073709551616.000000 */
+  {{.ldt = {0x00000000U, 0x80000000U, 0x3FFFU + 0x0040U, 1}}, -9.223372036854775808E18}  /* -18446744073709551616.000000 */
+};
+
+static const size_t n_tests_long_double = sizeof(tests_long_double) / sizeof(tests_long_double[0]);
+
+
+int main(void)
+{
+  int i, counter;
+
+  for (counter = i = 0; i < n_tests_long_double; i++)
+  {
+    long long int result = llrintl(tests_long_double[i].value.ld);
+
+    if (tests_long_double[i].should_be == result)
+      counter++;
+    else
+      printf("llrintl test failed:  value to round = %.6Lg  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) ? "llrintl test failed." : "llrintl test succeded.");
+
+  return 0;
+}
diff -aprNU5 djgpp.orig/tests/cygnus/t-lrint.c djgpp/tests/cygnus/t-lrint.c
--- djgpp.orig/tests/cygnus/t-lrint.c    1970-01-01 01:00:00 +0100
+++ djgpp/tests/cygnus/t-lrint.c    2013-09-18 21:39:52 +0100
@@ -0,0 +1,94 @@
+/* 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}},   -2147483648}, /* Big number. */
+  {{.dt = {0xFFFFFFFFU, 0x7FFFFU, 0x7FEU, 1}},   -2147483648}, /* Big -number. */
+
+  /* Infs. */
+  {{.dt = {0x0U, 0x0U, 0x7FFU, 0}},   -2147483648L}, /* Inf */
+  {{.dt = {0x0U, 0x0U, 0x7FFU, 1}},   -2147483648L}, /* -Inf */
+
+  /* NaNs. */
+  {{.dt = {0x1U, 0x0U, 0x7FFU, 0}},   -2147483648L}, /* SNaN */
+  {{.dt = {0x1U, 0x0U, 0x7FFU, 1}},   -2147483648L}, /* -SNaN */
+  {{.dt = {0x0U, 0xFFFFFU, 0x7FFU, 1}},   -2147483648L}, /* QNaN */
+  {{.dt = {0x0U, 0xFFFFFU, 0x7FFU, 0}},   -2147483648L}, /* -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}}, +2147483647L}, /* 2147483647.000000 */
+  {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0x01FU, 1}}, -2147483648L}, /* -2147483648.000000 */
+  {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0x020U, 0}}, -2147483648L}, /* 4294967296.000000 */
+  {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0x020U, 1}}, -2147483648L} /* -4294967296.000000 */
+};
+
+static const size_t n_tests_double = sizeof(tests_double) / sizeof(tests_double[0]);
+
+
+int main(void)
+{
+  int i, counter;
+
+  for (counter = i = 0; i < n_tests_double; i++)
+  {
+    long int result = lrint(tests_double[i].value.d);
+
+    if (tests_double[i].should_be == result)
+      counter++;
+    else
+      printf("lrint 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) ? "lrint test failed." : "lrint test succeded.");
+
+  return 0;
+}
diff -aprNU5 djgpp.orig/tests/cygnus/t-lrintf.c djgpp/tests/cygnus/t-lrintf.c
--- djgpp.orig/tests/cygnus/t-lrintf.c    1970-01-01 01:00:00 +0100
+++ djgpp/tests/cygnus/t-lrintf.c    2013-09-18 00:24:10 +0100
@@ -0,0 +1,103 @@
+/* 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}},   -2.147483648E9}, /* Big number. */
+  {{.ft = {0xFFFFU, 0xFEU, 1}},   -2.147483648E9}, /* Big -number. */
+
+  /* Infs. */
+  {{.ft = {0x0U, 0xFFU, 0}},   -2.147483648E9}, /* Inf */
+  {{.ft = {0x0U, 0xFFU, 1}},   -2.147483648E9}, /* -Inf */
+
+  /* NaNs. */
+  {{.ft = {0x1U, 0xFFU, 0}},   -2.147483648E9}, /* SNaN */
+  {{.ft = {0x1U, 0xFFU, 1}},   -2.147483648E9}, /* -SNaN */
+  {{.ft = {0x7FFFFFU, 0xFFU, 0}},   -2.147483648E9}, /* QNaN */
+  {{.ft = {0x7FFFFFU, 0xFFU, 1}},   -2.147483648E9}, /* -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}},  +2.147483648E9},  /* 2147483648.000000 */
+  {{.ft = {0x000000U, 0x7FU + 0x1FU, 1}},  -2.147483648E9},  /* -2147483648.000000 */
+  {{.ft = {0x000000U, 0x7FU + 0x20U, 0}},  -2.147483648E9},  /* 4294967296.000000 */
+  {{.ft = {0x000000U, 0x7FU + 0x20U, 1}},  -2.147483648E9},  /* -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 */
+
+};
+
+static const size_t n_tests_float = sizeof(tests_float) / sizeof(tests_float[0]);
+
+
+int main(void)
+{
+  int i, counter;
+
+  for (counter = i = 0; i < n_tests_float; i++)
+  {
+    long int result = lrintf(tests_float[i].value.f);
+
+    if (tests_float[i].should_be == result)
+      counter++;
+    else
+      printf("lrintf test failed:  value to round = %.6f  result = %ld  should be = %ld\n", tests_float[i].value.f, result, tests_float[i].should_be);
+  }
+  printf("%s\n", (counter < n_tests_float) ? "lrintf test failed." : "lrintf test succeded.");
+
+  return 0;
+}
diff -aprNU5 djgpp.orig/tests/cygnus/t-lrintl.c djgpp/tests/cygnus/t-lrintl.c
--- djgpp.orig/tests/cygnus/t-lrintl.c    1970-01-01 01:00:00 +0100
+++ djgpp/tests/cygnus/t-lrintl.c    2013-09-18 22:33:04 +0100
@@ -0,0 +1,96 @@
+/* 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}}, -2147483648L}, /* Big number. */
+  {{.ldt = {0xFFFFFFFFU, 0xFFFFFFFFU, 0x7FFEU, 1}}, -2147483648L}, /* Big -number. */
+
+  /* Infs. */
+  {{.ldt = {0x0U, 0x80000000U, 0x7FFFU, 0}},   -2147483648L}, /* Inf */
+  {{.ldt = {0x0U, 0x80000000U, 0x7FFFU, 1}},   -2147483648L}, /* -Inf */
+
+  /* NaNs. */
+  {{.ldt = {0x1U, 0x80000000U, 0x7FFFU, 0}},   -2147483648L}, /* SNaN */
+  {{.ldt = {0x1U, 0x80000000U, 0x7FFFU, 1}},   -2147483648L}, /* -SNaN */
+  {{.ldt = {0x0U, 0xFFFFFFFFU, 0x7FFFU, 0}},   -2147483648L}, /* QNaN */
+  {{.ldt = {0x0U, 0xFFFFFFFFU, 0x7FFFU, 1}},   -2147483648L}, /* -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}}, +2147483647L}, /* 2147483647.000000 */
+  {{.ldt = {0x00000000U, 0x80000000U, 0x3FFFU + 0x001FU, 1}}, -2147483648L}, /* -2147483648.000000 */
+  {{.ldt = {0x00000000U, 0x80000000U, 0x3FFFU + 0x0020U, 0}}, -2147483648L}, /* 4294967296.000000 */
+  {{.ldt = {0x00000000U, 0x80000000U, 0x3FFFU + 0x0020U, 1}}, -2147483648L}  /* -4294967296.000000 */
+};
+
+static const size_t n_tests_long_double = sizeof(tests_long_double) / sizeof(tests_long_double[0]);
+
+
+
+int main(void)
+{
+  int i, counter;
+
+  for (counter = i = 0; i < n_tests_long_double; i++)
+  {
+    long int result = lrintl(tests_long_double[i].value.ld);
+
+    if (tests_long_double[i].should_be == result)
+      counter++;
+    else
+      printf("lrintl test failed:  value to round = %.6Lg  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) ? "lrintl test failed." : "lrintl test succeded.");
+
+  return 0;
+}

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019