From d3f9671a7d1d27db78ea3d24b9edaf22e8751b70 Mon Sep 17 00:00:00 2001 From: David Schultz Date: Mon, 14 Jan 2008 02:12:07 +0000 Subject: Implement rintl(), nearbyintl(), lrintl(), and llrintl(). Thanks to bde@ for feedback and testing of rintl(). --- lib/msun/Makefile | 10 +++--- lib/msun/Symbol.map | 4 +++ lib/msun/amd64/Makefile.inc | 6 ++-- lib/msun/amd64/s_llrintl.S | 35 +++++++++++++++++++++ lib/msun/amd64/s_lrintl.S | 35 +++++++++++++++++++++ lib/msun/amd64/s_rintl.S | 43 +++++++++++++++++++++++++ lib/msun/i387/Makefile.inc | 3 +- lib/msun/i387/s_llrintl.S | 36 +++++++++++++++++++++ lib/msun/i387/s_lrintl.S | 35 +++++++++++++++++++++ lib/msun/i387/s_rintl.S | 43 +++++++++++++++++++++++++ lib/msun/man/lrint.3 | 24 +++++++++----- lib/msun/man/rint.3 | 34 +++++++++++--------- lib/msun/src/math.h | 8 ++--- lib/msun/src/s_llrintl.c | 9 ++++++ lib/msun/src/s_lrintl.c | 9 ++++++ lib/msun/src/s_nearbyint.c | 1 + lib/msun/src/s_rint.c | 6 ++++ lib/msun/src/s_rintl.c | 77 +++++++++++++++++++++++++++++++++++++++++++++ 18 files changed, 383 insertions(+), 35 deletions(-) create mode 100644 lib/msun/amd64/s_llrintl.S create mode 100644 lib/msun/amd64/s_lrintl.S create mode 100644 lib/msun/amd64/s_rintl.S create mode 100644 lib/msun/i387/s_llrintl.S create mode 100644 lib/msun/i387/s_lrintl.S create mode 100644 lib/msun/i387/s_rintl.S create mode 100644 lib/msun/src/s_llrintl.c create mode 100644 lib/msun/src/s_lrintl.c create mode 100644 lib/msun/src/s_rintl.c (limited to 'lib') diff --git a/lib/msun/Makefile b/lib/msun/Makefile index 34d23b2dc393..888cd8cae8d1 100644 --- a/lib/msun/Makefile +++ b/lib/msun/Makefile @@ -75,11 +75,11 @@ VERSION_DEF= ${LIBCDIR}/Versions.def SYMBOL_MAPS= ${SYM_MAPS} # C99 long double functions -COMMON_SRCS+= s_copysignl.c s_fabsl.c s_modfl.c +COMMON_SRCS+= s_copysignl.c s_fabsl.c s_llrintl.c s_lrintl.c s_modfl.c .if ${LDBL_PREC} != 53 # If long double != double use these; otherwise, we alias the double versions. COMMON_SRCS+= s_fmal.c s_frexpl.c s_logbl.c s_nanl.c \ - s_nextafterl.c s_nexttoward.c s_scalbnl.c + s_nextafterl.c s_nexttoward.c s_rintl.c s_scalbnl.c .endif # C99 complex functions @@ -150,7 +150,8 @@ MLINKS+=ilogb.3 ilogbf.3 ilogb.3 ilogbl.3 \ MLINKS+=j0.3 j1.3 j0.3 jn.3 j0.3 y0.3 j0.3 y1.3 j0.3 y1f.3 j0.3 yn.3 MLINKS+=j0.3 j0f.3 j0.3 j1f.3 j0.3 jnf.3 j0.3 y0f.3 j0.3 ynf.3 MLINKS+=lgamma.3 gamma.3 lgamma.3 gammaf.3 lgamma.3 lgammaf.3 lgamma.3 tgamma.3 -MLINKS+=lrint.3 llrint.3 lrint.3 llrintf.3 lrint.3 lrintf.3 +MLINKS+=lrint.3 llrint.3 lrint.3 llrintf.3 lrint.3 llrintl.3 \ + lrint.3 lrintf.3 lrint.3 lrintl.3 MLINKS+=lround.3 llround.3 lround.3 llroundf.3 lround.3 llroundl.3 \ lround.3 lroundf.3 lround.3 lroundl.3 MLINKS+=nan.3 nanf.3 nan.3 nanl.3 @@ -159,7 +160,8 @@ MLINKS+=nextafter.3 nexttoward.3 nextafter.3 nexttowardf.3 MLINKS+=nextafter.3 nexttowardl.3 MLINKS+=remainder.3 remainderf.3 MLINKS+=remainder.3 remquo.3 remainder.3 remquof.3 -MLINKS+=rint.3 rintf.3 rint.3 nearbyint.3 rint.3 nearbyintf.3 +MLINKS+=rint.3 rintf.3 rint.3 rintl.3 \ + rint.3 nearbyint.3 rint.3 nearbyintf.3 rint.3 nearbyintl.3 MLINKS+=round.3 roundf.3 round.3 roundl.3 MLINKS+=scalbn.3 scalbln.3 scalbn.3 scalblnf.3 scalbn.3 scalblnl.3 MLINKS+=scalbn.3 scalbnf.3 scalbn.3 scalbnl.3 diff --git a/lib/msun/Symbol.map b/lib/msun/Symbol.map index df309282264e..098202fc51e5 100644 --- a/lib/msun/Symbol.map +++ b/lib/msun/Symbol.map @@ -193,4 +193,8 @@ FBSD_1.1 { nan; nanf; nanl; + llrintl; + lrintl; + nearbyintl; + rintl; }; diff --git a/lib/msun/amd64/Makefile.inc b/lib/msun/amd64/Makefile.inc index 364a713a3018..c4f6094b5d2b 100644 --- a/lib/msun/amd64/Makefile.inc +++ b/lib/msun/amd64/Makefile.inc @@ -1,7 +1,7 @@ # $FreeBSD$ -ARCH_SRCS = e_sqrt.S e_sqrtf.S s_llrint.S s_llrintf.S \ - s_logbl.S s_lrint.S s_lrintf.S \ - s_remquo.S s_remquof.S s_scalbn.S s_scalbnf.S s_scalbnl.S +ARCH_SRCS = e_sqrt.S e_sqrtf.S s_llrint.S s_llrintf.S s_llrintl.S \ + s_logbl.S s_lrint.S s_lrintf.S s_lrintl.S \ + s_remquo.S s_remquof.S s_rintl.S s_scalbn.S s_scalbnf.S s_scalbnl.S LDBL_PREC = 64 SYM_MAPS += ${.CURDIR}/amd64/Symbol.map diff --git a/lib/msun/amd64/s_llrintl.S b/lib/msun/amd64/s_llrintl.S new file mode 100644 index 000000000000..a0e4f2be21cc --- /dev/null +++ b/lib/msun/amd64/s_llrintl.S @@ -0,0 +1,35 @@ +/*- + * Copyright (c) 2005 David Schultz + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +ENTRY(llrintl) + fldt 8(%rsp) + subq $8,%rsp + fistpll (%rsp) + popq %rax + ret diff --git a/lib/msun/amd64/s_lrintl.S b/lib/msun/amd64/s_lrintl.S new file mode 100644 index 000000000000..5e85cffc1ccc --- /dev/null +++ b/lib/msun/amd64/s_lrintl.S @@ -0,0 +1,35 @@ +/*- + * Copyright (c) 2008 David Schultz + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +ENTRY(lrintl) + fldt 8(%rsp) + subq $8,%rsp + fistpll (%rsp) + popq %rax + ret diff --git a/lib/msun/amd64/s_rintl.S b/lib/msun/amd64/s_rintl.S new file mode 100644 index 000000000000..9b9a22d5838d --- /dev/null +++ b/lib/msun/amd64/s_rintl.S @@ -0,0 +1,43 @@ +/* + * Copyright (c) 1993,94 Winning Strategies, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Winning Strategies, Inc. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* + * Written by: + * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc. + */ + +#include + +ENTRY(rintl) + fldt 8(%rsp) + frndint + ret diff --git a/lib/msun/i387/Makefile.inc b/lib/msun/i387/Makefile.inc index 393dfab5cf48..2fe0bcf3abd7 100644 --- a/lib/msun/i387/Makefile.inc +++ b/lib/msun/i387/Makefile.inc @@ -13,7 +13,8 @@ ARCH_SRCS+= e_log10f.S e_logf.S e_remainderf.S \ s_remquof.S s_rintf.S s_scalbnf.S s_significandf.S s_truncf.S # long double counterparts -ARCH_SRCS+= s_ceill.S s_copysignl.S s_floorl.S s_logbl.S s_scalbnl.S s_truncl.S +ARCH_SRCS+= s_ceill.S s_copysignl.S s_floorl.S s_llrintl.S \ + s_logbl.S s_lrintl.S s_rintl.S s_scalbnl.S s_truncl.S LDBL_PREC = 64 # XXX 64-bit format, but truncated to 53 bits SYM_MAPS += ${.CURDIR}/i387/Symbol.map diff --git a/lib/msun/i387/s_llrintl.S b/lib/msun/i387/s_llrintl.S new file mode 100644 index 000000000000..96d2c6bb43f8 --- /dev/null +++ b/lib/msun/i387/s_llrintl.S @@ -0,0 +1,36 @@ +/*- + * Copyright (c) 2005 David Schultz + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +ENTRY(llrintl) + fldt 4(%esp) + subl $8,%esp + fistpll (%esp) + popl %eax + popl %edx + ret diff --git a/lib/msun/i387/s_lrintl.S b/lib/msun/i387/s_lrintl.S new file mode 100644 index 000000000000..f2ff5380bab3 --- /dev/null +++ b/lib/msun/i387/s_lrintl.S @@ -0,0 +1,35 @@ +/*- + * Copyright (c) 2008 David Schultz + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +ENTRY(lrintl) + fldt 4(%esp) + subl $4,%esp + fistpl (%esp) + popl %eax + ret diff --git a/lib/msun/i387/s_rintl.S b/lib/msun/i387/s_rintl.S new file mode 100644 index 000000000000..5e1c3c3df5c1 --- /dev/null +++ b/lib/msun/i387/s_rintl.S @@ -0,0 +1,43 @@ +/* + * Copyright (c) 1993,94 Winning Strategies, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Winning Strategies, Inc. + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Written by: + * J.T. Conklin (jtc@wimsey.com), Winning Strategies, Inc. + */ + +#include + +RCSID("$FreeBSD$") + +ENTRY(rintl) + fldt 4(%esp) + frndint + ret diff --git a/lib/msun/man/lrint.3 b/lib/msun/man/lrint.3 index bae9c454563b..e5204353cb15 100644 --- a/lib/msun/man/lrint.3 +++ b/lib/msun/man/lrint.3 @@ -24,14 +24,16 @@ .\" .\" $FreeBSD$ .\" -.Dd January 11, 2005 +.Dd January 13, 2008 .Dt LRINT 3 .Os .Sh NAME .Nm llrint , .Nm llrintf , +.Nm llrintl , .Nm lrint , -.Nm lrintf +.Nm lrintf , +.Nm lrintl .Nd "convert to integer" .Sh LIBRARY .Lb libm @@ -41,10 +43,14 @@ .Fn llrint "double x" .Ft "long long" .Fn llrintf "float x" +.Ft "long long" +.Fn llrintl "long double x" .Ft long .Fn lrint "double x" .Ft long .Fn lrintf "float x" +.Ft long +.Fn lrintl "long double x" .Sh DESCRIPTION The .Fn lrint @@ -70,8 +76,10 @@ is equivalent to The .Fn llrint , .Fn llrintf , +.Fn llrintl , +.Fn lrintf , and -.Fn lrintf +.Fn lrintl functions differ from .Fn lrint only in their input and output types. @@ -81,14 +89,16 @@ only in their input and output types. .Xr rint 3 , .Xr round 3 .Sh STANDARDS +These functions conform to +.St -isoC-99 . +.Sh HISTORY The .Fn llrint , .Fn llrintf , .Fn lrint , and .Fn lrintf -functions conform to -.St -isoC-99 . -.Sh HISTORY -These routines first appeared in +routines first appeared in .Fx 5.4 . +The long double variants were introduced in +.Fx 8.0 . diff --git a/lib/msun/man/rint.3 b/lib/msun/man/rint.3 index c716f8d0277d..4ae7523ff137 100644 --- a/lib/msun/man/rint.3 +++ b/lib/msun/man/rint.3 @@ -28,14 +28,16 @@ .\" from: @(#)rint.3 5.1 (Berkeley) 5/2/91 .\" $FreeBSD$ .\" -.Dd July 5, 2004 +.Dd January 13, 2008 .Dt RINT 3 .Os .Sh NAME .Nm nearbyint , .Nm nearbyintf , +.Nm nearbyintl , .Nm rint , -.Nm rintf +.Nm rintf , +.Nm rintl .Nd round to integral value in floating-point format .Sh LIBRARY .Lb libm @@ -45,15 +47,20 @@ .Fn nearbyint "double x" .Ft float .Fn nearbyintf "float x" +.Ft long double +.Fn nearbyintl "long double x" .Ft double .Fn rint "double x" .Ft float .Fn rintf "float x" +.Ft long double +.Fn rintl "long double x" .Sh DESCRIPTION The -.Fn rint -and the -.Fn rintf +.Fn rint , +.Fn rintf , +and +.Fn rintl functions return the integral value nearest to .Fa x according to the prevailing rounding mode. @@ -61,9 +68,10 @@ These functions raise an inexact exception when the original argument is not an exact integer. .Pp The -.Fn nearbyint +.Fn nearbyint , +.Fn nearbyintf , and -.Fn nearbyintf +.Fn nearbyintl functions perform the same operation, except that they do not raise an inexact exception. .Sh SEE ALSO @@ -78,13 +86,7 @@ an inexact exception. .Xr math 3 , .Xr round 3 .Sh STANDARDS -The -.Fn nearbyint , -.Fn nearbyintf , -.Fn rint , -and -.Fn rintf -functions conform to +These functions conform to .St -isoC-99 . .Sh HISTORY A @@ -96,4 +98,6 @@ The and .Fn nearbyintf functions appeared in -.Fx 5.3 . +.Fx 5.3 , +and the long double variants were first available in +.Fx 8.0 . diff --git a/lib/msun/src/math.h b/lib/msun/src/math.h index 9f791ae02c1a..07bbd57c5022 100644 --- a/lib/msun/src/math.h +++ b/lib/msun/src/math.h @@ -429,8 +429,8 @@ int ilogbl(long double) __pure2; long double ldexpl(long double, int); #if 0 long double lgammal(long double); -long long llrintl(long double); #endif +long long llrintl(long double); long long llroundl(long double); #if 0 long double log10l(long double); @@ -440,14 +440,12 @@ long double log2l(long double); long double logbl(long double); #if 0 long double logl(long double); -long lrintl(long double); #endif +long lrintl(long double); long lroundl(long double); long double modfl(long double, long double *); /* fundamentally !__pure2 */ long double nanl(const char *) __pure2; -#if 0 long double nearbyintl(long double); -#endif long double nextafterl(long double, long double); double nexttoward(double, long double); float nexttowardf(float, long double); @@ -456,8 +454,8 @@ long double nexttowardl(long double, long double); long double powl(long double, long double); long double remainderl(long double, long double); long double remquol(long double, long double, int *); -long double rintl(long double); #endif +long double rintl(long double); long double roundl(long double); long double scalblnl(long double, long); long double scalbnl(long double, int); diff --git a/lib/msun/src/s_llrintl.c b/lib/msun/src/s_llrintl.c new file mode 100644 index 000000000000..6ef83759c314 --- /dev/null +++ b/lib/msun/src/s_llrintl.c @@ -0,0 +1,9 @@ +#include +__FBSDID("$FreeBSD$"); + +#define type long double +#define roundit rintl +#define dtype long long +#define fn llrintl + +#include "s_lrint.c" diff --git a/lib/msun/src/s_lrintl.c b/lib/msun/src/s_lrintl.c new file mode 100644 index 000000000000..497b442f32d7 --- /dev/null +++ b/lib/msun/src/s_lrintl.c @@ -0,0 +1,9 @@ +#include +__FBSDID("$FreeBSD$"); + +#define type long double +#define roundit rintl +#define dtype long +#define fn lrintl + +#include "s_lrint.c" diff --git a/lib/msun/src/s_nearbyint.c b/lib/msun/src/s_nearbyint.c index a075d2f48d63..12493d292809 100644 --- a/lib/msun/src/s_nearbyint.c +++ b/lib/msun/src/s_nearbyint.c @@ -52,3 +52,4 @@ fn(type x) \ DECL(double, nearbyint, rint) DECL(float, nearbyintf, rintf) +DECL(long double, nearbyintl, rintl) diff --git a/lib/msun/src/s_rint.c b/lib/msun/src/s_rint.c index 0a7bfc47a432..74a93318f831 100644 --- a/lib/msun/src/s_rint.c +++ b/lib/msun/src/s_rint.c @@ -24,6 +24,8 @@ static char rcsid[] = "$FreeBSD$"; * Inexact flag raised if x not equal to rint(x). */ +#include + #include "math.h" #include "math_private.h" @@ -85,3 +87,7 @@ rint(double x) *(volatile double *)&w = TWO52[sx]+x; /* clip any extra precision */ return w-TWO52[sx]; } + +#if (LDBL_MANT_DIG == 53) +__weak_reference(rint, rintl); +#endif diff --git a/lib/msun/src/s_rintl.c b/lib/msun/src/s_rintl.c new file mode 100644 index 000000000000..21dbbf6552fc --- /dev/null +++ b/lib/msun/src/s_rintl.c @@ -0,0 +1,77 @@ +/*- + * Copyright (c) 2008 David Schultz + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include + +#include "fpmath.h" + +static const long double +shift[2]={ +#if LDBL_MANT_DIG == 64 + 0x1.0p63, -0x1.0p63 +#elif LDBL_MANT_DIG == 113 + 0x1.0p112, -0x1.0p112 +#else +#error "Unsupported long double format" +#endif +}; + +long double +rintl(long double x) +{ + union IEEEl2bits u; + short sign; + + u.e = x; + + if (u.bits.exp >= LDBL_MANT_DIG + LDBL_MAX_EXP - 2) { + /* + * The biased exponent is greater than the number of digits + * in the mantissa, so x is inf, NaN, or an integer. + */ + if (u.bits.exp == 2 * LDBL_MAX_EXP - 1) + return (x + x); /* inf or NaN */ + else + return (x); + } + + /* + * The following code assumes that intermediate results are + * evaluated in long double precision. If they are evaluated in + * greater precision, double rounding will occur, and if they are + * evaluated in less precision (as on i386), results will be + * wildly incorrect. + */ + sign = u.bits.sign; + u.e = shift[sign] + x; + u.e -= shift[sign]; + u.bits.sign = sign; + return (u.e); +} -- cgit v1.2.3