delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2013/10/20/18:35:16

X-Authentication-Warning: delorie.com: mail set sender to djgpp-workers-bounces using -f
X-Recipient: djgpp-workers AT delorie DOT com
Message-ID: <52645811.5020201@gmx.de>
Date: Mon, 21 Oct 2013 00:24:17 +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: Re: Implementation of the [l]lrint[f|l] family of functions.
References: <523A2796 DOT 8040908 AT gmx DOT de>
In-Reply-To: <523A2796.8040908@gmx.de>
X-Provags-ID: V03:K0:8CGQVQ9E3St489FF/YFcphlN58RFVySq4qWatvgFmG5jncU89jE
dVx7+KnxzTDKrWN2waJyYvepIgR7eDoMOMerAT7XcIRRfEqsz42xPK5QwujXIW7F/kSfWEw
R1ozBVY8n4ejm5tFN3c55yz9YvmZLeJO8bYLRvqkSIT8PFksCAUfH/4VrebUHhZHdzSruEN
aV/8siOt6A9si4y4lmKrw==
Reply-To: djgpp-workers AT delorie DOT com

Am 19.09.2013 00:22, schrieb Juan Manuel Guerrero:
> 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.
[snip]

OFYI, committed the patch below.


Regards,
Juan M. Guerrero





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


     * /djgpp/tests/libc/c99/math/t-llrint.c: Check for llrint.

     * /djgpp/tests/libc/c99/math/t-llrintl.c: Check for llrintl.

     * /djgpp/tests/libc/c99/math/t-lrint.c: Check for llrintl.

     * /djgpp/tests/libc/c99/math/t-lrintf.c: Check for llrintl.

     * /djgpp/tests/libc/c99/math/t-lrintl.c: Check for llrintl.

     * djgpp/tests/cygnus/makefile: [l]lrint[f|l] function checks added to goal list.


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


     * djgpp/src/libc/c99/math/llrint.c: Assembler implementation of llrint.

     * djgpp/src/libc/c99/math/llrintf.c: Assembler implementation of llrintf.

     * djgpp/src/libc/c99/math/llrintl.c: Assembler implementation of llrintl.

     * djgpp/src/libc/c99/math/lrint.c: Assembler implementation of lrint.

     * djgpp/src/libc/c99/math/lrintf.c: Assembler implementation of lrintf.

     * djgpp/src/libc/c99/math/lrintl.c: Assembler implementation of lrintl.

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

     * djgpp/src/libc/c99/math/llrint.txh: Added documentation about llrint.

     * djgpp/src/libc/c99/math/llrintf.txh: Added documentation about llrintf.

     * djgpp/src/libc/c99/math/llrintl.txh: Added documentation about llrintl.

     * djgpp/src/libc/c99/math/lrint.txh: Added documentation about lrint.

     * djgpp/src/libc/c99/math/lrintf.txh: Added documentation about lrintf.

     * djgpp/src/libc/c99/math/lrintl.txh: Added documentation about lrintl.

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


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-10-14 22:37:24 +0100
+++ djgpp/include/libm/math.h    2013-10-14 22:39:38 +0100
@@ -156,10 +156,16 @@ extern double fmod __P((double, double))

  #if !defined(__STRICT_ANSI__) || defined(__cplusplus) || \
      defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L

  /* ISO C99 types and macros. */
+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 float truncf __P((float));
  extern double trunc __P((double));
  extern long double truncl __P((long double));
  #endif /* !defined (__STRICT_ANSI__) || defined(__cplusplus)
            || defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L */
diff -aprNU5 djgpp.orig/include/math.h djgpp/include/math.h
--- djgpp.orig/include/math.h    2013-10-14 22:37:24 +0100
+++ djgpp/include/math.h    2013-10-14 22:39:38 +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 23:24:52 +0100
+++ djgpp/src/docs/kb/wc204.txi    2013-10-14 22:39:38 +0100
@@ -1308,5 +1308,17 @@ 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.
+These functions are available in two versions.  One fast assembler version
+in @file{libc.a} and one accurate in @file{libm.a}.
diff -aprNU5 djgpp.orig/src/libc/c99/math/llrint.c djgpp/src/libc/c99/math/llrint.c
--- djgpp.orig/src/libc/c99/math/llrint.c    1970-01-01 01:00:00 +0100
+++ djgpp/src/libc/c99/math/llrint.c    2013-10-14 22:39:38 +0100
@@ -0,0 +1,14 @@
+/* Copyright (C) 2013 DJ Delorie, see COPYING.DJ for details */
+
+#include <math.h>
+
+
+long long int
+llrint(double x)
+{
+  long long int result;
+
+  asm("fistpll %0" : "=m" (result) : "t" (x) : "st");
+
+  return result;
+}
diff -aprNU5 djgpp.orig/src/libc/c99/math/llrint.txh djgpp/src/libc/c99/math/llrint.txh
--- djgpp.orig/src/libc/c99/math/llrint.txh    1970-01-01 01:00:00 +0100
+++ djgpp/src/libc/c99/math/llrint.txh    2013-10-14 22:39:38 +0100
@@ -0,0 +1,38 @@
+@c ----------------------------------------------------------------------
+@node llrint, math
+@vindex llrint
+@subheading Syntax
+
+@example
+#include <math.h>
+
+long long int llrint(double x);
+@end example
+
+@subheading Description
+
+The @code{llrint} functions round their argument to the nearest integer value,
+using the current rounding direction.
+
+Note that unlike @code{rint}, etc., the return type of these functions differs
+from that of their arguments.
+
+The function do not set @code{errno}.
+
+@subheading Return Value
+
+Which floating-point error reporting methods are available.
+The function returns the rounded integer value of @var{x}.
+If @var{x} is @code{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.
+
+@subheading Portability
+
+@portability ansi-c99, posix-1003.1-2001
+
+@subheading Example
+
+@example
+long long int result = llrint(3.1415926535897932384626433832795);
+@end example
diff -aprNU5 djgpp.orig/src/libc/c99/math/llrintf.c djgpp/src/libc/c99/math/llrintf.c
--- djgpp.orig/src/libc/c99/math/llrintf.c    1970-01-01 01:00:00 +0100
+++ djgpp/src/libc/c99/math/llrintf.c    2013-10-14 22:39:38 +0100
@@ -0,0 +1,14 @@
+/* Copyright (C) 2013 DJ Delorie, see COPYING.DJ for details */
+
+#include <math.h>
+
+
+long long int
+llrintf(float x)
+{
+  long long int result;
+
+  asm("fistpll %0" : "=m" (result) : "t" (x) : "st");
+
+  return result;
+}
diff -aprNU5 djgpp.orig/src/libc/c99/math/llrintf.txh djgpp/src/libc/c99/math/llrintf.txh
--- djgpp.orig/src/libc/c99/math/llrintf.txh    1970-01-01 01:00:00 +0100
+++ djgpp/src/libc/c99/math/llrintf.txh    2013-10-14 22:39:38 +0100
@@ -0,0 +1,38 @@
+@c ----------------------------------------------------------------------
+@node llrintf, math
+@vindex llrintf
+@subheading Syntax
+
+@example
+#include <math.h>
+
+long long int llrintf(float x);
+@end example
+
+@subheading Description
+
+The @code{llrintf} functions round their argument to the nearest integer value,
+using the current rounding direction.
+
+Note that unlike @code{rint}, etc., the return type of these functions differs
+from that of their arguments.
+
+The function do not set @code{errno}.
+
+@subheading Return Value
+
+Which floating-point error reporting methods are available.
+The function returns the rounded integer value of @var{x}.
+If @var{x} is @code{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.
+
+@subheading Portability
+
+@portability ansi-c99, posix-1003.1-2001
+
+@subheading Example
+
+@example
+long long int result = llrintf(3.1415926535897932384626433832795);
+@end example
diff -aprNU5 djgpp.orig/src/libc/c99/math/llrintl.c djgpp/src/libc/c99/math/llrintl.c
--- djgpp.orig/src/libc/c99/math/llrintl.c    1970-01-01 01:00:00 +0100
+++ djgpp/src/libc/c99/math/llrintl.c    2013-10-14 22:39:40 +0100
@@ -0,0 +1,14 @@
+/* Copyright (C) 2013 DJ Delorie, see COPYING.DJ for details */
+
+#include <math.h>
+
+
+long long int
+llrintl(long double x)
+{
+  long long int result;
+
+  asm("fistpll %0" : "=m" (result) : "t" (x) : "st");
+
+  return result;
+}
diff -aprNU5 djgpp.orig/src/libc/c99/math/llrintl.txh djgpp/src/libc/c99/math/llrintl.txh
--- djgpp.orig/src/libc/c99/math/llrintl.txh    1970-01-01 01:00:00 +0100
+++ djgpp/src/libc/c99/math/llrintl.txh    2013-10-14 22:39:40 +0100
@@ -0,0 +1,38 @@
+@c ----------------------------------------------------------------------
+@node llrintl, math
+@vindex llrintl
+@subheading Syntax
+
+@example
+#include <math.h>
+
+long long int llrintl(long double x);
+@end example
+
+@subheading Description
+
+The @code{llrintl} functions round their argument to the nearest integer value,
+using the current rounding direction.
+
+Note that unlike @code{rint}, etc., the return type of these functions differs
+from that of their arguments.
+
+The function do not set @code{errno}.
+
+@subheading Return Value
+
+Which floating-point error reporting methods are available.
+The function returns the rounded integer value of @var{x}.
+If @var{x} is @code{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.
+
+@subheading Portability
+
+@portability ansi-c99, posix-1003.1-2001
+
+@subheading Example
+
+@example
+long long int result = llrintl(3.1415926535897932384626433832795);
+@end example
diff -aprNU5 djgpp.orig/src/libc/c99/math/lrint.c djgpp/src/libc/c99/math/lrint.c
--- djgpp.orig/src/libc/c99/math/lrint.c    1970-01-01 01:00:00 +0100
+++ djgpp/src/libc/c99/math/lrint.c    2013-10-14 22:39:40 +0100
@@ -0,0 +1,14 @@
+/* Copyright (C) 2013 DJ Delorie, see COPYING.DJ for details */
+
+#include <math.h>
+
+
+long int
+lrint(double x)
+{
+  long int result;
+
+  asm("fistpl %0" : "=m" (result) : "t" (x) : "st");
+
+  return result;
+}
diff -aprNU5 djgpp.orig/src/libc/c99/math/lrint.txh djgpp/src/libc/c99/math/lrint.txh
--- djgpp.orig/src/libc/c99/math/lrint.txh    1970-01-01 01:00:00 +0100
+++ djgpp/src/libc/c99/math/lrint.txh    2013-10-14 22:39:40 +0100
@@ -0,0 +1,38 @@
+@c ----------------------------------------------------------------------
+@node lrint, math
+@vindex lrint
+@subheading Syntax
+
+@example
+#include <math.h>
+
+long int lrint(double x);
+@end example
+
+@subheading Description
+
+The @code{lrint} functions round their argument to the nearest integer value,
+using the current rounding direction.
+
+Note that unlike @code{rint}, etc., the return type of these functions differs
+from that of their arguments.
+
+The function do not set @code{errno}.
+
+@subheading Return Value
+
+Which floating-point error reporting methods are available.
+The function returns the rounded integer value of @var{x}.
+If @var{x} is @code{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.
+
+@subheading Portability
+
+@portability ansi-c99, posix-1003.1-2001
+
+@subheading Example
+
+@example
+long int result = lrint(3.1415926535897932384626433832795);
+@end example
diff -aprNU5 djgpp.orig/src/libc/c99/math/lrintf.c djgpp/src/libc/c99/math/lrintf.c
--- djgpp.orig/src/libc/c99/math/lrintf.c    1970-01-01 01:00:00 +0100
+++ djgpp/src/libc/c99/math/lrintf.c    2013-10-14 22:39:40 +0100
@@ -0,0 +1,14 @@
+/* Copyright (C) 2013 DJ Delorie, see COPYING.DJ for details */
+
+#include <math.h>
+
+
+long int
+lrintf(float x)
+{
+  long int result;
+
+  asm("fistpl %0" : "=m" (result) : "t" (x) : "st");
+
+  return result;
+}
diff -aprNU5 djgpp.orig/src/libc/c99/math/lrintf.txh djgpp/src/libc/c99/math/lrintf.txh
--- djgpp.orig/src/libc/c99/math/lrintf.txh    1970-01-01 01:00:00 +0100
+++ djgpp/src/libc/c99/math/lrintf.txh    2013-10-14 22:39:40 +0100
@@ -0,0 +1,38 @@
+@c ----------------------------------------------------------------------
+@node lrintf, math
+@vindex lrintf
+@subheading Syntax
+
+@example
+#include <math.h>
+
+long int lrintf(float x);
+@end example
+
+@subheading Description
+
+The @code{lrintf} functions round their argument to the nearest integer value,
+using the current rounding direction.
+
+Note that unlike @code{rint}, etc., the return type of these functions differs
+from that of their arguments.
+
+The function do not set @code{errno}.
+
+@subheading Return Value
+
+Which floating-point error reporting methods are available.
+The function returns the rounded integer value of @var{x}.
+If @var{x} is @code{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.
+
+@subheading Portability
+
+@portability ansi-c99, posix-1003.1-2001
+
+@subheading Example
+
+@example
+long int result = lrintf(3.1415926535897932384626433832795);
+@end example
diff -aprNU5 djgpp.orig/src/libc/c99/math/lrintl.c djgpp/src/libc/c99/math/lrintl.c
--- djgpp.orig/src/libc/c99/math/lrintl.c    1970-01-01 01:00:00 +0100
+++ djgpp/src/libc/c99/math/lrintl.c    2013-10-14 22:39:40 +0100
@@ -0,0 +1,14 @@
+/* Copyright (C) 2013 DJ Delorie, see COPYING.DJ for details */
+
+#include <math.h>
+
+
+long int
+lrintl(long double x)
+{
+  long int result;
+
+  asm("fistpl %0" : "=m" (result) : "t" (x) : "st");
+
+  return result;
+}
diff -aprNU5 djgpp.orig/src/libc/c99/math/lrintl.txh djgpp/src/libc/c99/math/lrintl.txh
--- djgpp.orig/src/libc/c99/math/lrintl.txh    1970-01-01 01:00:00 +0100
+++ djgpp/src/libc/c99/math/lrintl.txh    2013-10-14 22:39:40 +0100
@@ -0,0 +1,38 @@
+@c ----------------------------------------------------------------------
+@node lrintl, math
+@vindex lrintl
+@subheading Syntax
+
+@example
+#include <math.h>
+
+long int lrintl(long double x);
+@end example
+
+@subheading Description
+
+The @code{lrintl} functions round their argument to the nearest integer value,
+using the current rounding direction.
+
+Note that unlike @code{rint}, etc., the return type of these functions differs
+from that of their arguments.
+
+The function do not set @code{errno}.
+
+@subheading Return Value
+
+Which floating-point error reporting methods are available.
+The function returns the rounded integer value of @var{x}.
+If @var{x} is @code{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.
+
+@subheading Portability
+
+@portability ansi-c99, posix-1003.1-2001
+
+@subheading Example
+
+@example
+long int result = lrintl(3.1415926535897932384626433832795);
+@end example
diff -aprNU5 djgpp.orig/src/libc/c99/math/makefile djgpp/src/libc/c99/math/makefile
--- djgpp.orig/src/libc/c99/math/makefile    2008-04-06 23:06:40 +0100
+++ djgpp/src/libc/c99/math/makefile    2013-10-20 13:53:16 +0100
@@ -1,12 +1,19 @@
+# Copyright (C) 2013 DJ Delorie, see COPYING.DJ for details
  # Copyright (C) 2003 DJ Delorie, see COPYING.DJ for details
  # Copyright (C) 2002 DJ Delorie, see COPYING.DJ for details
  TOP=../..

  SRC += errhandl.c
  SRC += hugevalf.c
  SRC += hugevall.c
+SRC += lrintf.c
+SRC += lrint.c
+SRC += lrintl.c
+SRC += llrintf.c
+SRC += llrint.c
+SRC += llrintl.c
  SRC += nan_def.c
  SRC += nan.c
  SRC += nanf.c
  SRC += nanl.c
  SRC += fpclassf.S
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-10-20 13:48:56 +0100
@@ -0,0 +1,128 @@
+/* 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
+    llrintl
+
+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>
+
+#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 long int) * 8) - 2)
+#define MAGNITUDE_IS_LESS_THAN_ONE(exp)                      ((exp) < 0)
+#define MAGNITUDE_IS_LESS_THAN_ONE_HALF(exp)                 ((exp) < -1)
+#define IS_ZERO(num) ((((num).dt.mantissah & ~(1UL << BIN_DIGITS_IN_MANTISSAH)) == 0) && (((num).dt.mantissal & 0xFFFFFFFFUL) == 0) && (((num).dt.exponent & 0x07FFU) == 0))
+
+#define ROUND_MANTISSAH(num, unbiased_exponent)              ((long long int)(((uint64_t)(num).dt.mantissah | 0x00100000ULL) >> (BIN_DIGITS_IN_MANTISSAH - (unbiased_exponent))))
+#define ROUND_MANTISSAH_TO_INTEGER(num, unbiased_exponent) \
+(__gnuc_extension__ \
+ ({ \
+     (num).d = two52[(num).dt.sign] + x; \
+     (num).d -= two52[(num).dt.sign]; \
+     (unbiased_exponent) = (num).dt.exponent - DOUBLE_BIAS; \
+ \
+     result = MAGNITUDE_IS_LESS_THAN_ONE((unbiased_exponent)) || IS_ZERO((num)) ? 0 : ROUND_MANTISSAH((num), (unbiased_exponent));  \
+     (long long int)result; \
+ }) \
+)
+
+#define SHIFT_LEFT_MANTISSAH(num, unbiased_exponent) (((uint64_t)(num).dt.mantissah | 0x00100000ULL) << ((unbiased_exponent) - BIN_DIGITS_IN_MANTISSAH))
+#define CONVERT_MANTISSA_TO_INTEGER(num, unbiased_exponent)  ((long long int)(SHIFT_LEFT_MANTISSAH(num, unbiased_exponent) | (num).dt.mantissal << ((unbiased_exponent) - BIN_DIGITS_IN_FRACTION)))
+#define ROUND_MANTISSA(num, unbiased_exponent)               ((long long int)(SHIFT_LEFT_MANTISSAH(num, unbiased_exponent) | (num).dt.mantissal >> (BIN_DIGITS_IN_FRACTION - (unbiased_exponent))))
+#define ROUND_MANTISSA_TO_INTEGER(num, unbiased_exponent) \
+(__gnuc_extension__ \
+ ({ \
+     (num).d = two52[(num).dt.sign] + x; \
+     (num).d -= two52[(num).dt.sign]; \
+     (unbiased_exponent) = (num).dt.exponent - DOUBLE_BIAS; \
+ \
+     result = ((unbiased_exponent) == BIN_DIGITS_IN_MANTISSAH) ? (long long int)(num).dt.mantissah : ROUND_MANTISSA((num), (unbiased_exponent));  \
+     (long long int)result; \
+ }) \
+)
+
+
+/* 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;
+  long long int result;
+
+
+  ieee_value.d = x;
+  unbiased_exponent = ieee_value.dt.exponent - DOUBLE_BIAS;
+
+  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))
+    result = MAGNITUDE_IS_LESS_THAN_ONE_HALF(unbiased_exponent) ? 0 : ROUND_MANTISSAH_TO_INTEGER(ieee_value, unbiased_exponent);
+  else
+    result = ALL_DIGITS_ARE_SIGNIFICANT(unbiased_exponent) ? CONVERT_MANTISSA_TO_INTEGER(ieee_value, unbiased_exponent)  /* >= 2^63 is already an exact integer.  */
+                                                           : ROUND_MANTISSA_TO_INTEGER(ieee_value, unbiased_exponent);
+
+  return ieee_value.dt.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-10-20 13:48:56 +0100
@@ -0,0 +1,78 @@
+/* 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 FLOAT_BIAS (0x7FU)
+#define BIN_DIGITS_IN_FRACTION (23)    /*  Amount of binary digits in fraction part of mantissa. */
+#define ALL_DIGITS_ARE_SIGNIFICANT(exp)                      ((exp) > (BIN_DIGITS_IN_FRACTION - 1))
+#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 IS_ZERO(num) ((((num).ft.mantissa & ~(1ULL << BIN_DIGITS_IN_FRACTION)) == 0) && (((num).ft.exponent & 0xFFU) == 0))
+#define CONVERT_MANTISSA_TO_INTEGER(num, unbiased_exponent)  ((long long int)((uint32_t)(num).ft.mantissa | 0x00800000ULL) << ((unbiased_exponent) - BIN_DIGITS_IN_FRACTION))
+#define ROUND_MANTISSA(num, unbiased_exponent)               ((long long int)((uint32_t)(num).ft.mantissa | 0x00800000ULL) >> (BIN_DIGITS_IN_FRACTION - (unbiased_exponent)))
+#define ROUND_MANTISSA_TO_INTEGER(num, unbiased_exponent) \
+(__gnuc_extension__ \
+ ({ \
+     (num).f = two23[(num).ft.sign] + x; \
+     (num).f -= two23[(num).ft.sign]; \
+     (unbiased_exponent) = (num).ft.exponent - FLOAT_BIAS; \
+ \
+     result = MAGNITUDE_IS_LESS_THAN_ONE((unbiased_exponent)) || IS_ZERO((num)) ? 0 : ROUND_MANTISSA((num), (unbiased_exponent));  \
+     (long long int)result; \
+ }) \
+)
+
+
+/* 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 long int
+llrintf(float x)
+#else
+long long int
+llrintf(x)
+float x;
+#endif
+{
+  _float_union_t ieee_value;
+  int unbiased_exponent;
+  long long int result;
+
+
+  ieee_value.f = x;
+  unbiased_exponent = ieee_value.ft.exponent - FLOAT_BIAS;
+
+  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_HALF(unbiased_exponent))
+      result = 0;
+    else
+      result = ALL_DIGITS_ARE_SIGNIFICANT(unbiased_exponent) ? CONVERT_MANTISSA_TO_INTEGER(ieee_value, unbiased_exponent)  /* >= 2^23 is already an exact integer.  */
+                                                             : ROUND_MANTISSA_TO_INTEGER(ieee_value, unbiased_exponent);
+
+    return ieee_value.ft.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-10-20 13:48:56 +0100
@@ -0,0 +1,92 @@
+/* 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 long int) * 8) - 2)
+#define MAGNITUDE_IS_LESS_THAN_ONE(exp)                      ((exp) < 0)
+#define MAGNITUDE_IS_LESS_THAN_ONE_HALF(exp)                 ((exp) < -1)
+#define IS_ZERO(num) ((((num).ldt.mantissah & 0xFFFFFFFFUL) == 0) && (((num).ldt.mantissal & 0xFFFFFFFFUL) == 0) && (((num).ldt.exponent & 0x7FFFU) == 0))
+
+#define ROUND_MANTISSAH(num, unbiased_exponent)              ((long long int)((uint64_t)(num).ldt.mantissah >> (BIN_DIGITS_IN_MANTISSAH - (unbiased_exponent))))
+#define ROUND_MANTISSAH_TO_INTEGER(num, unbiased_exponent) \
+(__gnuc_extension__ \
+ ({ \
+     (num).ld = two63[(num).ldt.sign] + x; \
+     (num).ld -= two63[(num).ldt.sign]; \
+     (unbiased_exponent) = (num).ldt.exponent - LONG_DOUBLE_BIAS; \
+ \
+     result = MAGNITUDE_IS_LESS_THAN_ONE((unbiased_exponent)) || IS_ZERO((num)) ? 0 : ROUND_MANTISSAH((num), (unbiased_exponent));  \
+     (long long int)result; \
+ }) \
+)
+
+#define SHIFT_LEFT_MANTISSAH(num, unbiased_exponent) ((uint64_t)(num).ldt.mantissah << ((unbiased_exponent) - BIN_DIGITS_IN_MANTISSAH))
+#define CONVERT_MANTISSA_TO_INTEGER(num, unbiased_exponent)  ((long long int)(SHIFT_LEFT_MANTISSAH(num, unbiased_exponent) | (num).ldt.mantissal << ((unbiased_exponent) - BIN_DIGITS_IN_FRACTION)))
+#define ROUND_MANTISSA(num, unbiased_exponent)               ((long long int)(SHIFT_LEFT_MANTISSAH(num, unbiased_exponent) | (num).ldt.mantissal >> (BIN_DIGITS_IN_FRACTION - (unbiased_exponent))))
+#define ROUND_MANTISSA_TO_INTEGER(num, unbiased_exponent) \
+(__gnuc_extension__ \
+ ({ \
+     (num).ld = two63[(num).ldt.sign] + x; \
+     (num).ld -= two63[(num).ldt.sign]; \
+     (unbiased_exponent) = (num).ldt.exponent - LONG_DOUBLE_BIAS; \
+ \
+     result = ((unbiased_exponent) == BIN_DIGITS_IN_MANTISSAH) ? (long long int)(num).ldt.mantissah : ROUND_MANTISSA((num), (unbiased_exponent));  \
+     (long long int)result; \
+ }) \
+)
+
+
+/* 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;
+  long long int result;
+
+
+  ieee_value.ld = x;
+  unbiased_exponent = ieee_value.ldt.exponent - LONG_DOUBLE_BIAS;
+
+  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))
+    result = MAGNITUDE_IS_LESS_THAN_ONE_HALF(unbiased_exponent) ? 0 : ROUND_MANTISSAH_TO_INTEGER(ieee_value, unbiased_exponent);
+  else
+    result = ALL_DIGITS_ARE_SIGNIFICANT(unbiased_exponent) ? CONVERT_MANTISSA_TO_INTEGER(ieee_value, unbiased_exponent)
+                                                           : ROUND_MANTISSA_TO_INTEGER(ieee_value, unbiased_exponent);
+
+  return ieee_value.ldt.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-10-20 13:48:56 +0100
@@ -0,0 +1,128 @@
+/* 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
+    lrintl
+
+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>
+
+#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 IS_ZERO(num) ((((num).dt.mantissah & ~(1L << BIN_DIGITS_IN_MANTISSAH)) == 0) && (((num).dt.mantissal & 0xFFFFFFFFUL) == 0) && (((num).dt.exponent & 0x07FFU) == 0))
+
+#define ROUND_MANTISSAH(num, unbiased_exponent)              ((long int)(((uint32_t)(num).dt.mantissah | 0x00100000UL) >> (BIN_DIGITS_IN_MANTISSAH - (unbiased_exponent))))
+#define ROUND_MANTISSAH_TO_INTEGER(num, unbiased_exponent) \
+(__gnuc_extension__ \
+ ({ \
+     (num).d = two52[(num).dt.sign] + x; \
+     (num).d -= two52[(num).dt.sign]; \
+     (unbiased_exponent) = (num).dt.exponent - DOUBLE_BIAS; \
+ \
+     result = MAGNITUDE_IS_LESS_THAN_ONE((unbiased_exponent)) || IS_ZERO((num)) ? 0 : ROUND_MANTISSAH((num), (unbiased_exponent));  \
+     (long int)result; \
+ }) \
+)
+
+#define SHIFT_LEFT_MANTISSAH(num, unbiased_exponent) (((uint32_t)(num).dt.mantissah | 0x00100000UL) << ((unbiased_exponent) - BIN_DIGITS_IN_MANTISSAH))
+#define CONVERT_MANTISSA_TO_INTEGER(num, unbiased_exponent)  ((long int)(SHIFT_LEFT_MANTISSAH(num, unbiased_exponent) | (num).dt.mantissal << ((unbiased_exponent) - BIN_DIGITS_IN_FRACTION)))
+#define ROUND_MANTISSA(num, unbiased_exponent)               ((long int)(SHIFT_LEFT_MANTISSAH(num, unbiased_exponent) | (num).dt.mantissal >> (BIN_DIGITS_IN_FRACTION - (unbiased_exponent))))
+#define ROUND_MANTISSA_TO_INTEGER(num, unbiased_exponent) \
+(__gnuc_extension__ \
+ ({ \
+     (num).d = two52[(num).dt.sign] + x; \
+     (num).d -= two52[(num).dt.sign]; \
+     (unbiased_exponent) = (num).dt.exponent - DOUBLE_BIAS; \
+ \
+     result = ((unbiased_exponent) == BIN_DIGITS_IN_MANTISSAH) ? (long int)(num).dt.mantissah : ROUND_MANTISSA((num), (unbiased_exponent));  \
+     (long int)result; \
+ }) \
+)
+
+
+/* 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;
+  long int result;
+
+
+  ieee_value.d = x;
+  unbiased_exponent = ieee_value.dt.exponent - DOUBLE_BIAS;
+
+  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))
+    result = MAGNITUDE_IS_LESS_THAN_ONE_HALF(unbiased_exponent) ? 0 : ROUND_MANTISSAH_TO_INTEGER(ieee_value, unbiased_exponent);
+  else
+    result = ALL_DIGITS_ARE_SIGNIFICANT(unbiased_exponent) ? CONVERT_MANTISSA_TO_INTEGER(ieee_value, unbiased_exponent)  /* >= 2^52 is already an exact integer iff long int is 64 bit.  But this is not the case with djgpp.  */
+                                                           : ROUND_MANTISSA_TO_INTEGER(ieee_value, unbiased_exponent);
+
+  return ieee_value.dt.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-10-20 13:45:16 +0100
@@ -0,0 +1,77 @@
+/* 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 FLOAT_BIAS (0x7FU)
+#define BIN_DIGITS_IN_FRACTION (23)    /*  Amount of binary digits in fraction part of mantissa. */
+#define ALL_DIGITS_ARE_SIGNIFICANT(exp)                      ((exp) > (BIN_DIGITS_IN_FRACTION - 1))
+#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 IS_ZERO(num) ((((num).ft.mantissa & ~(1UL << BIN_DIGITS_IN_FRACTION)) == 0) && (((num).ft.exponent & 0xFFU) == 0))
+#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(num, unbiased_exponent)               ((long int)((uint32_t)(num).ft.mantissa | 0x00800000UL) >> (BIN_DIGITS_IN_FRACTION - (unbiased_exponent)))
+#define ROUND_MANTISSA_TO_INTEGER(num, unbiased_exponent) \
+(__gnuc_extension__ \
+ ({ \
+     (num).f = two23[(num).ft.sign] + x; \
+     (num).f -= two23[(num).ft.sign]; \
+     (unbiased_exponent) = (num).ft.exponent - FLOAT_BIAS; \
+ \
+     result = MAGNITUDE_IS_LESS_THAN_ONE((unbiased_exponent)) || IS_ZERO((num)) ? 0 : ROUND_MANTISSA((num), (unbiased_exponent));  \
+     (long int)result; \
+ }) \
+)
+
+
+/* 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;
+  long int result;
+
+
+  ieee_value.f = x;
+  unbiased_exponent = ieee_value.ft.exponent - FLOAT_BIAS;
+
+  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_HALF(unbiased_exponent))
+      result = 0;
+    else
+      result = ALL_DIGITS_ARE_SIGNIFICANT(unbiased_exponent) ? CONVERT_MANTISSA_TO_INTEGER(ieee_value, unbiased_exponent)  /* >= 2^23 is already an exact integer.  */
+                                                             : ROUND_MANTISSA_TO_INTEGER(ieee_value, unbiased_exponent);
+    return ieee_value.ft.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-10-20 13:45:18 +0100
@@ -0,0 +1,91 @@
+/* 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 IS_ZERO(num) ((((num).ldt.mantissah & 0xFFFFFFFFUL) == 0) && (((num).ldt.mantissal & 0xFFFFFFFFUL) == 0) && (((num).ldt.exponent & 0x7FFFU) == 0))
+#define ROUND_MANTISSAH(num, unbiased_exponent)              ((long int)((uint32_t)(num).ldt.mantissah >> (BIN_DIGITS_IN_MANTISSAH - (unbiased_exponent))))
+#define ROUND_MANTISSAH_TO_INTEGER(num, unbiased_exponent) \
+(__gnuc_extension__ \
+ ({ \
+     (num).ld = two63[(num).ldt.sign] + x; \
+     (num).ld -= two63[(num).ldt.sign]; \
+     (unbiased_exponent) = (num).ldt.exponent - LONG_DOUBLE_BIAS; \
+ \
+     result = MAGNITUDE_IS_LESS_THAN_ONE((unbiased_exponent)) || IS_ZERO((num)) ? 0 : ROUND_MANTISSAH((num), (unbiased_exponent));  \
+     (long int)result; \
+ }) \
+)
+
+#define SHIFT_LEFT_MANTISSAH(num, unbiased_exponent) ((uint32_t)(num).ldt.mantissah << ((unbiased_exponent) - BIN_DIGITS_IN_MANTISSAH))
+#define CONVERT_MANTISSA_TO_INTEGER(num, unbiased_exponent)  ((long int)(SHIFT_LEFT_MANTISSAH(num, unbiased_exponent) | (num).ldt.mantissal << ((unbiased_exponent) - BIN_DIGITS_IN_FRACTION)))
+#define ROUND_MANTISSA(num, unbiased_exponent)               ((long int)(SHIFT_LEFT_MANTISSAH(num, unbiased_exponent) | (num).ldt.mantissal >> (BIN_DIGITS_IN_FRACTION - (unbiased_exponent))))
+#define ROUND_MANTISSA_TO_INTEGER(num, unbiased_exponent) \
+(__gnuc_extension__ \
+ ({ \
+     (num).ld = two63[(num).ldt.sign] + x; \
+     (num).ld -= two63[(num).ldt.sign]; \
+     (unbiased_exponent) = (num).ldt.exponent - LONG_DOUBLE_BIAS; \
+ \
+     result = ((unbiased_exponent) == BIN_DIGITS_IN_MANTISSAH) ? (long int)(num).ldt.mantissah : ROUND_MANTISSA((num), (unbiased_exponent));  \
+     (long int)result; \
+ }) \
+)
+
+
+/* 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;
+  long int result;
+
+
+  ieee_value.ld = x;
+  unbiased_exponent = ieee_value.ldt.exponent - LONG_DOUBLE_BIAS;
+
+  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))
+    result = MAGNITUDE_IS_LESS_THAN_ONE_HALF(unbiased_exponent) ? 0 : ROUND_MANTISSAH_TO_INTEGER(ieee_value, unbiased_exponent);
+  else
+    result = ALL_DIGITS_ARE_SIGNIFICANT(unbiased_exponent) ? CONVERT_MANTISSA_TO_INTEGER(ieee_value, unbiased_exponent)  /* >= 2^63 is already an exact integer iff long int is 64 bit.  */
+                                                           : ROUND_MANTISSA_TO_INTEGER(ieee_value, unbiased_exponent);
+
+  return ieee_value.ldt.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:24 +0100
+++ djgpp/src/libm/math/makefile    2013-10-14 22:39:40 +0100
@@ -165,21 +165,28 @@ SRC += sf_infinity.c
  SRC += sf_isinf.c
  SRC += sf_nan.c
  SRC += trunc.c
  SRC += truncf.c
  SRC += truncl.c
+SRC += lrint.c
+SRC += lrintf.c
+SRC += lrintl.c
+SRC += llrint.c
+SRC += llrintf.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 20:06:48 +0100
+++ djgpp/src/libm/math/math.texi    2013-10-14 22:39:40 +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,11 @@ 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-10-14 22:37:24 +0100
+++ djgpp/tests/cygnus/makefile    2013-10-14 22:39:40 +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 > ttest.results
      ./t-truncf.exe >> ttest.results
      ./t-truncl.exe >> ttest.results
+    ./t-lrintf.exe >> ttest.results
+    ./t-lrint.exe >> ttest.results
+    ./t-lrintl.exe >> ttest.results
+    ./t-llrint.exe >> ttest.results
+    ./t-llrintl.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-
@@ -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 ttest.results t-trunc*.o
+    cd $(HERE); $(RM) $(OFILES) $(VEC_OFILES) *~ *.exe mtest.results ttest.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-10-14 22:39:40 +0100
@@ -0,0 +1,107 @@
+/* Copyright (C) 2013 DJ Delorie, see COPYING.DJ for details */
+
+/*  Shall give the same results than /djgpp/tests/libc/c99/math/t-llrint.c  */
+
+
+#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)
+{
+  unsigned 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-10-14 22:39:42 +0100
@@ -0,0 +1,128 @@
+/* Copyright (C) 2013 DJ Delorie, see COPYING.DJ for details */
+
+/*  Shall give the same results than /djgpp/tests/libc/c99/math/t-llrintl.c  */
+
+
+#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)
+{
+  unsigned 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-10-14 22:39:42 +0100
@@ -0,0 +1,97 @@
+/* Copyright (C) 2013 DJ Delorie, see COPYING.DJ for details */
+
+/*  Shall give the same results than /djgpp/tests/libc/c99/math/t-lrint.c  */
+
+
+#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}},   -2147483648UL}, /* Big number. */
+  {{.dt = {0xFFFFFFFFU, 0x7FFFFU, 0x7FEU, 1}},   -2147483648UL}, /* Big -number. */
+
+  /* Infs. */
+  {{.dt = {0x0U, 0x0U, 0x7FFU, 0}},   -2147483648UL}, /* Inf */
+  {{.dt = {0x0U, 0x0U, 0x7FFU, 1}},   -2147483648UL}, /* -Inf */
+
+  /* NaNs. */
+  {{.dt = {0x1U, 0x0U, 0x7FFU, 0}},   -2147483648UL}, /* SNaN */
+  {{.dt = {0x1U, 0x0U, 0x7FFU, 1}},   -2147483648UL}, /* -SNaN */
+  {{.dt = {0x0U, 0xFFFFFU, 0x7FFU, 1}},   -2147483648UL}, /* QNaN */
+  {{.dt = {0x0U, 0xFFFFFU, 0x7FFU, 0}},   -2147483648UL}, /* -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}}, -2147483648UL}, /* -2147483648.000000 */
+  {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0x020U, 0}}, -2147483648UL}, /* 4294967296.000000 */
+  {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0x020U, 1}}, -2147483648UL} /* -4294967296.000000 */
+};
+
+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 = 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-10-14 22:39:42 +0100
@@ -0,0 +1,139 @@
+/* Copyright (C) 2013 DJ Delorie, see COPYING.DJ for details */
+
+/*  Shall give the same results than /djgpp/tests/libc/c99/math/t-lrintf.c  */
+
+
+#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 */
+
+  /*  Number greater than 2**32 thus all digits are significant and will not be truncated.  */
+  {{.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 = {0x000000U, 0x7FU + 0xFFFFFFFFU, 0}},  0},  /* 0.500000 */
+  {{.ft = {0x000000U, 0x7FU + 0xFFFFFFFFU, 1}},  -0},  /* -0.500000 */
+  {{.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 */
+
+  /*  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}},  65536},  /* 65536.5000000 */
+  {{.ft = {0x000040U, 0x7FU + 0x10U, 1}},  -65536},  /* -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 = 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-10-14 22:39:42 +0100
@@ -0,0 +1,99 @@
+/* Copyright (C) 2013 DJ Delorie, see COPYING.DJ for details */
+
+/*  Shall give the same results than /djgpp/tests/libc/c99/math/t-lrintl.c  */
+
+
+#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}}, -2147483648UL}, /* Big number. */
+  {{.ldt = {0xFFFFFFFFU, 0xFFFFFFFFU, 0x7FFEU, 1}}, -2147483648UL}, /* Big -number. */
+
+  /* Infs. */
+  {{.ldt = {0x0U, 0x80000000U, 0x7FFFU, 0}},   -2147483648UL}, /* Inf */
+  {{.ldt = {0x0U, 0x80000000U, 0x7FFFU, 1}},   -2147483648UL}, /* -Inf */
+
+  /* NaNs. */
+  {{.ldt = {0x1U, 0x80000000U, 0x7FFFU, 0}},   -2147483648UL}, /* SNaN */
+  {{.ldt = {0x1U, 0x80000000U, 0x7FFFU, 1}},   -2147483648UL}, /* -SNaN */
+  {{.ldt = {0x0U, 0xFFFFFFFFU, 0x7FFFU, 0}},   -2147483648UL}, /* QNaN */
+  {{.ldt = {0x0U, 0xFFFFFFFFU, 0x7FFFU, 1}},   -2147483648UL}, /* -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}}, -2147483648UL}, /* -2147483648.000000 */
+  {{.ldt = {0x00000000U, 0x80000000U, 0x3FFFU + 0x0020U, 0}}, -2147483648UL}, /* 4294967296.000000 */
+  {{.ldt = {0x00000000U, 0x80000000U, 0x3FFFU + 0x0020U, 1}}, -2147483648UL}  /* -4294967296.000000 */
+};
+
+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 = 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;
+}
diff -aprNU5 djgpp.orig/tests/libc/c99/math/makefile djgpp/tests/libc/c99/math/makefile
--- djgpp.orig/tests/libc/c99/math/makefile    2013-03-23 12:55:00 +0100
+++ djgpp/tests/libc/c99/math/makefile    2013-10-14 22:39:42 +0100
@@ -2,7 +2,12 @@ TOP=../..

  SRC += t-fpclas.c
  SRC += t-nan.c
  SRC += t-nan2.c
  SRC += t-ismac.c
+SRC += t-llrint.c
+SRC += t-llrintl.c
+SRC += t-lrint.c
+SRC += t-lrintf.c
+SRC += t-lrintl.c

  include $(TOP)/../makefile.inc
diff -aprNU5 djgpp.orig/tests/libc/c99/math/t-llrint.c djgpp/tests/libc/c99/math/t-llrint.c
--- djgpp.orig/tests/libc/c99/math/t-llrint.c    1970-01-01 01:00:00 +0100
+++ djgpp/tests/libc/c99/math/t-llrint.c    2013-10-14 22:39:42 +0100
@@ -0,0 +1,107 @@
+/* Copyright (C) 2013 DJ Delorie, see COPYING.DJ for details */
+
+/*  Shall give the same results than /djgpp/tests/cygnus/t-llrint.c  */
+
+
+#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)
+{
+  unsigned 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/libc/c99/math/t-llrintl.c djgpp/tests/libc/c99/math/t-llrintl.c
--- djgpp.orig/tests/libc/c99/math/t-llrintl.c    1970-01-01 01:00:00 +0100
+++ djgpp/tests/libc/c99/math/t-llrintl.c    2013-10-14 22:39:42 +0100
@@ -0,0 +1,128 @@
+/* Copyright (C) 2013 DJ Delorie, see COPYING.DJ for details */
+
+/*  Shall give the same results than /djgpp/tests/cygnus/t-llrintl.c  */
+
+
+#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)
+{
+  unsigned 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/libc/c99/math/t-lrint.c djgpp/tests/libc/c99/math/t-lrint.c
--- djgpp.orig/tests/libc/c99/math/t-lrint.c    1970-01-01 01:00:00 +0100
+++ djgpp/tests/libc/c99/math/t-lrint.c    2013-10-14 22:39:42 +0100
@@ -0,0 +1,97 @@
+/* Copyright (C) 2013 DJ Delorie, see COPYING.DJ for details */
+
+/*  Shall give the same results than /djgpp/tests/cygnus/t-lrint.c */
+
+
+#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)
+{
+  unsigned 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/libc/c99/math/t-lrintf.c djgpp/tests/libc/c99/math/t-lrintf.c
--- djgpp.orig/tests/libc/c99/math/t-lrintf.c    1970-01-01 01:00:00 +0100
+++ djgpp/tests/libc/c99/math/t-lrintf.c    2013-10-14 22:39:42 +0100
@@ -0,0 +1,106 @@
+/* Copyright (C) 2013 DJ Delorie, see COPYING.DJ for details */
+
+/*  Shall give the same results than /djgpp/tests/cygnus/t-lrintf.c  */
+
+
+#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)
+{
+  unsigned 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/libc/c99/math/t-lrintl.c djgpp/tests/libc/c99/math/t-lrintl.c
--- djgpp.orig/tests/libc/c99/math/t-lrintl.c    1970-01-01 01:00:00 +0100
+++ djgpp/tests/libc/c99/math/t-lrintl.c    2013-10-14 22:39:42 +0100
@@ -0,0 +1,99 @@
+/* Copyright (C) 2013 DJ Delorie, see COPYING.DJ for details */
+
+/*  Shall give the same results than /djgpp/tests/cygnus/t-lrintl.c  */
+
+
+#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)
+{
+  unsigned 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;
+}






2013-10-20  Juan Manuel Guerrero  <juan DOT guerrero AT gmx DOT de>


     * /djgpp/tests/libc/c99/math/t-llrint.c: Check for llrint.

     * /djgpp/tests/libc/c99/math/t-llrintl.c: Check for llrintl.

     * /djgpp/tests/libc/c99/math/t-lrint.c: Check for llrintl.

     * /djgpp/tests/libc/c99/math/t-lrintf.c: Check for llrintl.

     * /djgpp/tests/libc/c99/math/t-lrintl.c: Check for llrintl.

     * djgpp/tests/cygnus/makefile: [l]lrint[f|l] function checks added to goal list.


2013-10-20  Juan Manuel Guerrero  <juan DOT guerrero AT gmx DOT de>


     * djgpp/src/libm/math/lrint.c: Define ieee_value as volatile or it is outmized away.

     * djgpp/src/libm/math/lrintl.c: Define ieee_value as volatile or it is outmized away.






diff -aprNU5 djgpp.orig/src/libm/math/llrint.c djgpp/src/libm/math/llrint.c
--- djgpp.orig/src/libm/math/llrint.c    2013-10-20 14:02:18 +0100
+++ djgpp/src/libm/math/llrint.c    2013-10-20 23:34:08 +0100
@@ -58,11 +58,11 @@ ANSI C, POSIX

  #define ROUND_MANTISSAH(num, unbiased_exponent)              ((long long int)(((uint64_t)(num).dt.mantissah | 0x00100000ULL) >> (BIN_DIGITS_IN_MANTISSAH - (unbiased_exponent))))
  #define ROUND_MANTISSAH_TO_INTEGER(num, unbiased_exponent) \
  (__gnuc_extension__ \
({ \
-     (num).d = two52[(num).dt.sign] + x; \
+     (num).d += two52[(num).dt.sign]; \
       (num).d -= two52[(num).dt.sign]; \
       (unbiased_exponent) = (num).dt.exponent - DOUBLE_BIAS; \
\
       result = MAGNITUDE_IS_LESS_THAN_ONE((unbiased_exponent)) || IS_ZERO((num)) ? 0 : ROUND_MANTISSAH((num), (unbiased_exponent));  \
       (long long int)result; \
@@ -73,11 +73,11 @@ ANSI C, POSIX
  #define CONVERT_MANTISSA_TO_INTEGER(num, unbiased_exponent)  ((long long int)(SHIFT_LEFT_MANTISSAH(num, unbiased_exponent) | (num).dt.mantissal << ((unbiased_exponent) - BIN_DIGITS_IN_FRACTION)))
  #define ROUND_MANTISSA(num, unbiased_exponent)               ((long long int)(SHIFT_LEFT_MANTISSAH(num, unbiased_exponent) | (num).dt.mantissal >> (BIN_DIGITS_IN_FRACTION - (unbiased_exponent))))
  #define ROUND_MANTISSA_TO_INTEGER(num, unbiased_exponent) \
  (__gnuc_extension__ \
({ \
-     (num).d = two52[(num).dt.sign] + x; \
+     (num).d += two52[(num).dt.sign]; \
       (num).d -= two52[(num).dt.sign]; \
       (unbiased_exponent) = (num).dt.exponent - DOUBLE_BIAS; \
\
       result = ((unbiased_exponent) == BIN_DIGITS_IN_MANTISSAH) ? (long long int)(num).dt.mantissah : ROUND_MANTISSA((num), (unbiased_exponent));  \
       (long long int)result; \
@@ -106,23 +106,26 @@ llrint(double x)
  long long int
  llrint(x)
  double x;
  #endif
  {
-  _double_union_t ieee_value;
+  volatile _double_union_t ieee_value;
    int unbiased_exponent;
-  long long int result;


    ieee_value.d = x;
    unbiased_exponent = ieee_value.dt.exponent - DOUBLE_BIAS;

    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))
-    result = MAGNITUDE_IS_LESS_THAN_ONE_HALF(unbiased_exponent) ? 0 : ROUND_MANTISSAH_TO_INTEGER(ieee_value, unbiased_exponent);
    else
-    result = ALL_DIGITS_ARE_SIGNIFICANT(unbiased_exponent) ? CONVERT_MANTISSA_TO_INTEGER(ieee_value, unbiased_exponent)  /* >= 2^63 is already an exact integer.  */
-                                                           : ROUND_MANTISSA_TO_INTEGER(ieee_value, unbiased_exponent);
+  {
+    long long int result;

-  return ieee_value.dt.sign ? -result : result;
+    if (NO_SIGNIFICANT_DIGITS_IN_MANTISSAL(unbiased_exponent))
+      result = MAGNITUDE_IS_LESS_THAN_ONE_HALF(unbiased_exponent) ? 0 : ROUND_MANTISSAH_TO_INTEGER(ieee_value, unbiased_exponent);
+    else
+      result = ALL_DIGITS_ARE_SIGNIFICANT(unbiased_exponent) ? CONVERT_MANTISSA_TO_INTEGER(ieee_value, unbiased_exponent)  /* >= 2^63 is already an exact integer.  */
+                                                             : ROUND_MANTISSA_TO_INTEGER(ieee_value, unbiased_exponent);
+    return ieee_value.dt.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    2013-10-20 14:02:20 +0100
+++ djgpp/src/libm/math/llrintf.c    2013-10-20 23:34:08 +0100
@@ -15,16 +15,16 @@
  #define ALL_DIGITS_ARE_SIGNIFICANT(exp)                      ((exp) > (BIN_DIGITS_IN_FRACTION - 1))
  #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 IS_ZERO(num) ((((num).ft.mantissa & ~(1ULL << BIN_DIGITS_IN_FRACTION)) == 0) && (((num).ft.exponent & 0xFFU) == 0))
-#define CONVERT_MANTISSA_TO_INTEGER(num, unbiased_exponent)  ((long long int)((uint32_t)(num).ft.mantissa | 0x00800000ULL) << ((unbiased_exponent) - BIN_DIGITS_IN_FRACTION))
-#define ROUND_MANTISSA(num, unbiased_exponent)               ((long long int)((uint32_t)(num).ft.mantissa | 0x00800000ULL) >> (BIN_DIGITS_IN_FRACTION - (unbiased_exponent)))
+#define CONVERT_MANTISSA_TO_INTEGER(num, unbiased_exponent)  ((long long int)(((uint32_t)(num).ft.mantissa | 0x00800000ULL) << ((unbiased_exponent) - BIN_DIGITS_IN_FRACTION)))
+#define ROUND_MANTISSA(num, unbiased_exponent)               ((long long int)(((uint32_t)(num).ft.mantissa | 0x00800000ULL) >> (BIN_DIGITS_IN_FRACTION - (unbiased_exponent))))
  #define ROUND_MANTISSA_TO_INTEGER(num, unbiased_exponent) \
  (__gnuc_extension__ \
({ \
-     (num).f = two23[(num).ft.sign] + x; \
+     (num).f += two23[(num).ft.sign]; \
       (num).f -= two23[(num).ft.sign]; \
       (unbiased_exponent) = (num).ft.exponent - FLOAT_BIAS; \
\
       result = MAGNITUDE_IS_LESS_THAN_ONE((unbiased_exponent)) || IS_ZERO((num)) ? 0 : ROUND_MANTISSA((num), (unbiased_exponent));  \
       (long long int)result; \
@@ -53,26 +53,26 @@ llrintf(float x)
  long long int
  llrintf(x)
  float x;
  #endif
  {
-  _float_union_t ieee_value;
+  volatile _float_union_t ieee_value;
    int unbiased_exponent;
-  long long int result;


    ieee_value.f = x;
    unbiased_exponent = ieee_value.ft.exponent - FLOAT_BIAS;

    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
    {
+    long long int result;
+
      if (MAGNITUDE_IS_LESS_THAN_ONE_HALF(unbiased_exponent))
        result = 0;
      else
        result = ALL_DIGITS_ARE_SIGNIFICANT(unbiased_exponent) ? CONVERT_MANTISSA_TO_INTEGER(ieee_value, unbiased_exponent)  /* >= 2^23 is already an exact integer.  */
                                                               : ROUND_MANTISSA_TO_INTEGER(ieee_value, unbiased_exponent);
-
      return ieee_value.ft.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    2013-10-20 14:02:22 +0100
+++ djgpp/src/libm/math/llrintl.c    2013-10-20 23:34:08 +0100
@@ -22,11 +22,11 @@

  #define ROUND_MANTISSAH(num, unbiased_exponent)              ((long long int)((uint64_t)(num).ldt.mantissah >> (BIN_DIGITS_IN_MANTISSAH - (unbiased_exponent))))
  #define ROUND_MANTISSAH_TO_INTEGER(num, unbiased_exponent) \
  (__gnuc_extension__ \
({ \
-     (num).ld = two63[(num).ldt.sign] + x; \
+     (num).ld += two63[(num).ldt.sign]; \
       (num).ld -= two63[(num).ldt.sign]; \
       (unbiased_exponent) = (num).ldt.exponent - LONG_DOUBLE_BIAS; \
\
       result = MAGNITUDE_IS_LESS_THAN_ONE((unbiased_exponent)) || IS_ZERO((num)) ? 0 : ROUND_MANTISSAH((num), (unbiased_exponent));  \
       (long long int)result; \
@@ -37,11 +37,11 @@
  #define CONVERT_MANTISSA_TO_INTEGER(num, unbiased_exponent)  ((long long int)(SHIFT_LEFT_MANTISSAH(num, unbiased_exponent) | (num).ldt.mantissal << ((unbiased_exponent) - BIN_DIGITS_IN_FRACTION)))
  #define ROUND_MANTISSA(num, unbiased_exponent)               ((long long int)(SHIFT_LEFT_MANTISSAH(num, unbiased_exponent) | (num).ldt.mantissal >> (BIN_DIGITS_IN_FRACTION - (unbiased_exponent))))
  #define ROUND_MANTISSA_TO_INTEGER(num, unbiased_exponent) \
  (__gnuc_extension__ \
({ \
-     (num).ld = two63[(num).ldt.sign] + x; \
+     (num).ld += two63[(num).ldt.sign]; \
       (num).ld -= two63[(num).ldt.sign]; \
       (unbiased_exponent) = (num).ldt.exponent - LONG_DOUBLE_BIAS; \
\
       result = ((unbiased_exponent) == BIN_DIGITS_IN_MANTISSAH) ? (long long int)(num).ldt.mantissah : ROUND_MANTISSA((num), (unbiased_exponent));  \
       (long long int)result; \
@@ -70,23 +70,26 @@ llrintl(long double x)
  long long int
  llrintl(x)
  long double x;
  #endif
  {
-  _longdouble_union_t ieee_value;
+  volatile _longdouble_union_t ieee_value;
    int unbiased_exponent;
-  long long int result;


    ieee_value.ld = x;
    unbiased_exponent = ieee_value.ldt.exponent - LONG_DOUBLE_BIAS;

    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))
-    result = MAGNITUDE_IS_LESS_THAN_ONE_HALF(unbiased_exponent) ? 0 : ROUND_MANTISSAH_TO_INTEGER(ieee_value, unbiased_exponent);
    else
-    result = ALL_DIGITS_ARE_SIGNIFICANT(unbiased_exponent) ? CONVERT_MANTISSA_TO_INTEGER(ieee_value, unbiased_exponent)
-                                                           : ROUND_MANTISSA_TO_INTEGER(ieee_value, unbiased_exponent);
+  {
+    long long int result;

-  return ieee_value.ldt.sign ? -result : result;
+    if (NO_SIGNIFICANT_DIGITS_IN_MANTISSAL(unbiased_exponent))
+      result = MAGNITUDE_IS_LESS_THAN_ONE_HALF(unbiased_exponent) ? 0 : ROUND_MANTISSAH_TO_INTEGER(ieee_value, unbiased_exponent);
+    else
+      result = ALL_DIGITS_ARE_SIGNIFICANT(unbiased_exponent) ? CONVERT_MANTISSA_TO_INTEGER(ieee_value, unbiased_exponent)
+                                                             : ROUND_MANTISSA_TO_INTEGER(ieee_value, unbiased_exponent);
+    return ieee_value.ldt.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    2013-10-20 14:02:24 +0100
+++ djgpp/src/libm/math/lrint.c    2013-10-20 23:34:06 +0100
@@ -58,11 +58,11 @@ ANSI C, POSIX

  #define ROUND_MANTISSAH(num, unbiased_exponent)              ((long int)(((uint32_t)(num).dt.mantissah | 0x00100000UL) >> (BIN_DIGITS_IN_MANTISSAH - (unbiased_exponent))))
  #define ROUND_MANTISSAH_TO_INTEGER(num, unbiased_exponent) \
  (__gnuc_extension__ \
({ \
-     (num).d = two52[(num).dt.sign] + x; \
+     (num).d += two52[(num).dt.sign]; \
       (num).d -= two52[(num).dt.sign]; \
       (unbiased_exponent) = (num).dt.exponent - DOUBLE_BIAS; \
\
       result = MAGNITUDE_IS_LESS_THAN_ONE((unbiased_exponent)) || IS_ZERO((num)) ? 0 : ROUND_MANTISSAH((num), (unbiased_exponent));  \
       (long int)result; \
@@ -73,11 +73,11 @@ ANSI C, POSIX
  #define CONVERT_MANTISSA_TO_INTEGER(num, unbiased_exponent)  ((long int)(SHIFT_LEFT_MANTISSAH(num, unbiased_exponent) | (num).dt.mantissal << ((unbiased_exponent) - BIN_DIGITS_IN_FRACTION)))
  #define ROUND_MANTISSA(num, unbiased_exponent)               ((long int)(SHIFT_LEFT_MANTISSAH(num, unbiased_exponent) | (num).dt.mantissal >> (BIN_DIGITS_IN_FRACTION - (unbiased_exponent))))
  #define ROUND_MANTISSA_TO_INTEGER(num, unbiased_exponent) \
  (__gnuc_extension__ \
({ \
-     (num).d = two52[(num).dt.sign] + x; \
+     (num).d += two52[(num).dt.sign]; \
       (num).d -= two52[(num).dt.sign]; \
       (unbiased_exponent) = (num).dt.exponent - DOUBLE_BIAS; \
\
       result = ((unbiased_exponent) == BIN_DIGITS_IN_MANTISSAH) ? (long int)(num).dt.mantissah : ROUND_MANTISSA((num), (unbiased_exponent));  \
       (long int)result; \
@@ -106,23 +106,26 @@ lrint(double x)
  long int
  lrint(x)
  double x;
  #endif
  {
-  _double_union_t ieee_value;
+  volatile _double_union_t ieee_value;
    int unbiased_exponent;
-  long int result;


    ieee_value.d = x;
    unbiased_exponent = ieee_value.dt.exponent - DOUBLE_BIAS;

    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))
-    result = MAGNITUDE_IS_LESS_THAN_ONE_HALF(unbiased_exponent) ? 0 : ROUND_MANTISSAH_TO_INTEGER(ieee_value, unbiased_exponent);
    else
-    result = ALL_DIGITS_ARE_SIGNIFICANT(unbiased_exponent) ? CONVERT_MANTISSA_TO_INTEGER(ieee_value, unbiased_exponent)  /* >= 2^52 is already an exact integer iff long int is 64 bit.  But this is not the case with djgpp.  */
-                                                           : ROUND_MANTISSA_TO_INTEGER(ieee_value, unbiased_exponent);
+  {
+    long int result;

-  return ieee_value.dt.sign ? -result : result;
+    if (NO_SIGNIFICANT_DIGITS_IN_MANTISSAL(unbiased_exponent))
+      result = MAGNITUDE_IS_LESS_THAN_ONE_HALF(unbiased_exponent) ? 0 : ROUND_MANTISSAH_TO_INTEGER(ieee_value, unbiased_exponent);
+    else
+      result = ALL_DIGITS_ARE_SIGNIFICANT(unbiased_exponent) ? CONVERT_MANTISSA_TO_INTEGER(ieee_value, unbiased_exponent)  /* >= 2^52 is already an exact integer iff long int is 64 bit.  But this is not the case with djgpp.  */
+                                                             : ROUND_MANTISSA_TO_INTEGER(ieee_value, unbiased_exponent);
+    return ieee_value.dt.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    2013-10-20 14:02:26 +0100
+++ djgpp/src/libm/math/lrintf.c    2013-10-20 23:34:06 +0100
@@ -15,16 +15,16 @@
  #define ALL_DIGITS_ARE_SIGNIFICANT(exp)                      ((exp) > (BIN_DIGITS_IN_FRACTION - 1))
  #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 IS_ZERO(num) ((((num).ft.mantissa & ~(1UL << BIN_DIGITS_IN_FRACTION)) == 0) && (((num).ft.exponent & 0xFFU) == 0))
-#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(num, unbiased_exponent)               ((long int)((uint32_t)(num).ft.mantissa | 0x00800000UL) >> (BIN_DIGITS_IN_FRACTION - (unbiased_exponent)))
+#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(num, unbiased_exponent)               ((long int)(((uint32_t)(num).ft.mantissa | 0x00800000UL) >> (BIN_DIGITS_IN_FRACTION - (unbiased_exponent))))
  #define ROUND_MANTISSA_TO_INTEGER(num, unbiased_exponent) \
  (__gnuc_extension__ \
({ \
-     (num).f = two23[(num).ft.sign] + x; \
+     (num).f += two23[(num).ft.sign]; \
       (num).f -= two23[(num).ft.sign]; \
       (unbiased_exponent) = (num).ft.exponent - FLOAT_BIAS; \
\
       result = MAGNITUDE_IS_LESS_THAN_ONE((unbiased_exponent)) || IS_ZERO((num)) ? 0 : ROUND_MANTISSA((num), (unbiased_exponent));  \
       (long int)result; \
@@ -53,22 +53,23 @@ lrintf(float x)
  long int
  lrintf(x)
  float x;
  #endif
  {
-  _float_union_t ieee_value;
+  volatile _float_union_t ieee_value;
    int unbiased_exponent;
-  long int result;


    ieee_value.f = x;
    unbiased_exponent = ieee_value.ft.exponent - FLOAT_BIAS;

    if (MAGNITUDE_IS_TOO_LARGE(unbiased_exponent))  /* The number is too large.  */
      return (long int)x;                           /* It is left implementation defined what happens.  */
    else
    {
+    long int result;
+
      if (MAGNITUDE_IS_LESS_THAN_ONE_HALF(unbiased_exponent))
        result = 0;
      else
        result = ALL_DIGITS_ARE_SIGNIFICANT(unbiased_exponent) ? CONVERT_MANTISSA_TO_INTEGER(ieee_value, unbiased_exponent)  /* >= 2^23 is already an exact integer.  */
                                                               : ROUND_MANTISSA_TO_INTEGER(ieee_value, unbiased_exponent);
diff -aprNU5 djgpp.orig/src/libm/math/lrintl.c djgpp/src/libm/math/lrintl.c
--- djgpp.orig/src/libm/math/lrintl.c    2013-10-20 14:02:28 +0100
+++ djgpp/src/libm/math/lrintl.c    2013-10-20 23:34:10 +0100
@@ -21,11 +21,11 @@
  #define IS_ZERO(num) ((((num).ldt.mantissah & 0xFFFFFFFFUL) == 0) && (((num).ldt.mantissal & 0xFFFFFFFFUL) == 0) && (((num).ldt.exponent & 0x7FFFU) == 0))
  #define ROUND_MANTISSAH(num, unbiased_exponent)              ((long int)((uint32_t)(num).ldt.mantissah >> (BIN_DIGITS_IN_MANTISSAH - (unbiased_exponent))))
  #define ROUND_MANTISSAH_TO_INTEGER(num, unbiased_exponent) \
  (__gnuc_extension__ \
({ \
-     (num).ld = two63[(num).ldt.sign] + x; \
+     (num).ld += two63[(num).ldt.sign]; \
       (num).ld -= two63[(num).ldt.sign]; \
       (unbiased_exponent) = (num).ldt.exponent - LONG_DOUBLE_BIAS; \
\
       result = MAGNITUDE_IS_LESS_THAN_ONE((unbiased_exponent)) || IS_ZERO((num)) ? 0 : ROUND_MANTISSAH((num), (unbiased_exponent));  \
       (long int)result; \
@@ -36,11 +36,11 @@
  #define CONVERT_MANTISSA_TO_INTEGER(num, unbiased_exponent)  ((long int)(SHIFT_LEFT_MANTISSAH(num, unbiased_exponent) | (num).ldt.mantissal << ((unbiased_exponent) - BIN_DIGITS_IN_FRACTION)))
  #define ROUND_MANTISSA(num, unbiased_exponent)               ((long int)(SHIFT_LEFT_MANTISSAH(num, unbiased_exponent) | (num).ldt.mantissal >> (BIN_DIGITS_IN_FRACTION - (unbiased_exponent))))
  #define ROUND_MANTISSA_TO_INTEGER(num, unbiased_exponent) \
  (__gnuc_extension__ \
({ \
-     (num).ld = two63[(num).ldt.sign] + x; \
+     (num).ld += two63[(num).ldt.sign]; \
       (num).ld -= two63[(num).ldt.sign]; \
       (unbiased_exponent) = (num).ldt.exponent - LONG_DOUBLE_BIAS; \
\
       result = ((unbiased_exponent) == BIN_DIGITS_IN_MANTISSAH) ? (long int)(num).ldt.mantissah : ROUND_MANTISSA((num), (unbiased_exponent));  \
       (long int)result; \
@@ -69,23 +69,26 @@ lrintl(long double x)
  long int
  lrintl(x)
  long double x;
  #endif
  {
-  _longdouble_union_t ieee_value;
+  volatile _longdouble_union_t ieee_value;
    int unbiased_exponent;
-  long int result;


    ieee_value.ld = x;
    unbiased_exponent = ieee_value.ldt.exponent - LONG_DOUBLE_BIAS;

    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))
-    result = MAGNITUDE_IS_LESS_THAN_ONE_HALF(unbiased_exponent) ? 0 : ROUND_MANTISSAH_TO_INTEGER(ieee_value, unbiased_exponent);
    else
-    result = ALL_DIGITS_ARE_SIGNIFICANT(unbiased_exponent) ? CONVERT_MANTISSA_TO_INTEGER(ieee_value, unbiased_exponent)  /* >= 2^63 is already an exact integer iff long int is 64 bit.  */
-                                                           : ROUND_MANTISSA_TO_INTEGER(ieee_value, unbiased_exponent);
+  {
+    long int result;

-  return ieee_value.ldt.sign ? -result : result;
+    if (NO_SIGNIFICANT_DIGITS_IN_MANTISSAL(unbiased_exponent))
+      result = MAGNITUDE_IS_LESS_THAN_ONE_HALF(unbiased_exponent) ? 0 : ROUND_MANTISSAH_TO_INTEGER(ieee_value, unbiased_exponent);
+    else
+      result = ALL_DIGITS_ARE_SIGNIFICANT(unbiased_exponent) ? CONVERT_MANTISSA_TO_INTEGER(ieee_value, unbiased_exponent)  /* >= 2^63 is already an exact integer iff long int is 64 bit.  */
+                                                             : ROUND_MANTISSA_TO_INTEGER(ieee_value, unbiased_exponent);
+    return ieee_value.ldt.sign ? -result : result;
+  }
  }
diff -aprNU5 djgpp.orig/tests/libc/c99/math/t-lrint.c djgpp/tests/libc/c99/math/t-lrint.c
--- djgpp.orig/tests/libc/c99/math/t-lrint.c    2013-10-20 14:04:10 +0100
+++ djgpp/tests/libc/c99/math/t-lrint.c    2013-10-20 23:53:28 +0100
@@ -26,22 +26,22 @@ static const entry_t tests_double[] =
    {{.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. */
+  {{.dt = {0xFFFFFFFFU, 0x7FFFFU, 0x7FEU, 0}},   -2147483648UL}, /* Big number. */
+  {{.dt = {0xFFFFFFFFU, 0x7FFFFU, 0x7FEU, 1}},   -2147483648UL}, /* Big -number. */

    /* Infs. */
-  {{.dt = {0x0U, 0x0U, 0x7FFU, 0}},   -2147483648L}, /* Inf */
-  {{.dt = {0x0U, 0x0U, 0x7FFU, 1}},   -2147483648L}, /* -Inf */
+  {{.dt = {0x0U, 0x0U, 0x7FFU, 0}},   -2147483648UL}, /* Inf */
+  {{.dt = {0x0U, 0x0U, 0x7FFU, 1}},   -2147483648UL}, /* -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 */
+  {{.dt = {0x1U, 0x0U, 0x7FFU, 0}},   -2147483648UL}, /* SNaN */
+  {{.dt = {0x1U, 0x0U, 0x7FFU, 1}},   -2147483648UL}, /* -SNaN */
+  {{.dt = {0x0U, 0xFFFFFU, 0x7FFU, 1}},   -2147483648UL}, /* QNaN */
+  {{.dt = {0x0U, 0xFFFFFU, 0x7FFU, 0}},   -2147483648UL}, /* -QNaN */


    /* Number. */
    {{.dt = {0x54442D18U, 0x921FBU, 0x3FFU + 0x001U, 0}},   +3}, /* PI */
    {{.dt = {0x54442D18U, 0x921FBU, 0x3FFU + 0x001U, 1}},   -3}, /* -PI */
@@ -67,14 +67,14 @@ static const entry_t tests_double[] =
    {{.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 */
+  {{.dt = {0xFFC00000U, 0xFFFFFU, 0x3FFU + 0x01EU, 0}}, +2147483647LL}, /* 2147483647.000000 */
+  {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0x01FU, 1}}, -2147483648UL}, /* -2147483648.000000 */
+  {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0x020U, 0}}, -2147483648UL}, /* 4294967296.000000 */
+  {{.dt = {0x00000000U, 0x00000U, 0x3FFU + 0x020U, 1}}, -2147483648UL} /* -4294967296.000000 */
  };

  static const size_t n_tests_double = sizeof(tests_double) / sizeof(tests_double[0]);


diff -aprNU5 djgpp.orig/tests/libc/c99/math/t-lrintl.c djgpp/tests/libc/c99/math/t-lrintl.c
--- djgpp.orig/tests/libc/c99/math/t-lrintl.c    2013-10-20 14:04:12 +0100
+++ djgpp/tests/libc/c99/math/t-lrintl.c    2013-10-20 23:55:26 +0100
@@ -27,22 +27,22 @@ static const entry_t tests_long_double[]
    {{.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. */
+  {{.ldt = {0xFFFFFFFFU, 0xFFFFFFFFU, 0x7FFEU, 0}}, -2147483648UL}, /* Big number. */
+  {{.ldt = {0xFFFFFFFFU, 0xFFFFFFFFU, 0x7FFEU, 1}}, -2147483648UL}, /* Big -number. */

    /* Infs. */
-  {{.ldt = {0x0U, 0x80000000U, 0x7FFFU, 0}},   -2147483648L}, /* Inf */
-  {{.ldt = {0x0U, 0x80000000U, 0x7FFFU, 1}},   -2147483648L}, /* -Inf */
+  {{.ldt = {0x0U, 0x80000000U, 0x7FFFU, 0}},   -2147483648UL}, /* Inf */
+  {{.ldt = {0x0U, 0x80000000U, 0x7FFFU, 1}},   -2147483648UL}, /* -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 */
+  {{.ldt = {0x1U, 0x80000000U, 0x7FFFU, 0}},   -2147483648UL}, /* SNaN */
+  {{.ldt = {0x1U, 0x80000000U, 0x7FFFU, 1}},   -2147483648UL}, /* -SNaN */
+  {{.ldt = {0x0U, 0xFFFFFFFFU, 0x7FFFU, 0}},   -2147483648UL}, /* QNaN */
+  {{.ldt = {0x0U, 0xFFFFFFFFU, 0x7FFFU, 1}},   -2147483648UL}, /* -QNaN */

    /* Number. */
    {{.ldt = {0x2168C000U, 0xC90FDAA2U, 0x3FFFU + 0x0001U, 0}}, +3}, /* PI */
    {{.ldt = {0x2168C000U, 0xC90FDAA2U, 0x3FFFU + 0x0001U, 1}}, -3}, /* -PI */

@@ -68,14 +68,14 @@ static const entry_t tests_long_double[]
    {{.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 */
+  {{.ldt = {0x00000000U, 0xFFFFFFFEU, 0x3FFFU + 0x001EU, 0}}, +2147483647LL}, /* 2147483647.000000 */
+  {{.ldt = {0x00000000U, 0x80000000U, 0x3FFFU + 0x001FU, 1}}, -2147483648UL}, /* -2147483648.000000 */
+  {{.ldt = {0x00000000U, 0x80000000U, 0x3FFFU + 0x0020U, 0}}, -2147483648UL}, /* 4294967296.000000 */
+  {{.ldt = {0x00000000U, 0x80000000U, 0x3FFFU + 0x0020U, 1}}, -2147483648UL}  /* -4294967296.000000 */
  };

  static const size_t n_tests_long_double = sizeof(tests_long_double) / sizeof(tests_long_double[0]);



- Raw text -


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