Module Name: src Committed By: christos Date: Tue Apr 2 18:39:51 UTC 2024
Modified Files: src/lib/libm/src: s_fabsl.c s_rintl.c Log Message: PR/58054: Martin Husemann: fix bug in expsign extraction and only use the code for the floating point formats where it works (does not work for 112 bit mantisa in sparc64) To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/lib/libm/src/s_fabsl.c cvs rdiff -u -r1.5 -r1.6 src/lib/libm/src/s_rintl.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/lib/libm/src/s_fabsl.c diff -u src/lib/libm/src/s_fabsl.c:1.6 src/lib/libm/src/s_fabsl.c:1.7 --- src/lib/libm/src/s_fabsl.c:1.6 Sun Feb 25 14:26:33 2024 +++ src/lib/libm/src/s_fabsl.c Tue Apr 2 14:39:51 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: s_fabsl.c,v 1.6 2024/02/25 19:26:33 christos Exp $ */ +/* $NetBSD: s_fabsl.c,v 1.7 2024/04/02 18:39:51 christos Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -26,7 +26,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ #include <sys/cdefs.h> -__RCSID("$NetBSD: s_fabsl.c,v 1.6 2024/02/25 19:26:33 christos Exp $"); +__RCSID("$NetBSD: s_fabsl.c,v 1.7 2024/04/02 18:39:51 christos Exp $"); #include <math.h> #include <machine/ieee.h> @@ -47,7 +47,6 @@ fabsl(long double x) return (ux.extu_ld); } #else -#if 0 /* defined in libc */ long double fabsl(long double x) @@ -55,4 +54,3 @@ fabsl(long double x) return fabs(x); } #endif -#endif Index: src/lib/libm/src/s_rintl.c diff -u src/lib/libm/src/s_rintl.c:1.5 src/lib/libm/src/s_rintl.c:1.6 --- src/lib/libm/src/s_rintl.c:1.5 Wed Aug 21 09:04:44 2013 +++ src/lib/libm/src/s_rintl.c Tue Apr 2 14:39:51 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: s_rintl.c,v 1.5 2013/08/21 13:04:44 martin Exp $ */ +/* $NetBSD: s_rintl.c,v 1.6 2024/04/02 18:39:51 christos Exp $ */ /*- * Copyright (c) 2008 David Schultz <d...@freebsd.org> @@ -30,7 +30,7 @@ #if 0 __FBSDID("$FreeBSD: src/lib/msun/src/s_rintl.c,v 1.5 2008/02/22 11:59:05 bde Exp $"); #else -__RCSID("$NetBSD: s_rintl.c,v 1.5 2013/08/21 13:04:44 martin Exp $"); +__RCSID("$NetBSD: s_rintl.c,v 1.6 2024/04/02 18:39:51 christos Exp $"); #endif #include <float.h> @@ -40,17 +40,19 @@ __RCSID("$NetBSD: s_rintl.c,v 1.5 2013/0 #include "math_private.h" #ifdef __HAVE_LONG_DOUBLE + +# if EXT_FRACBITS == 64 || EXT_FRACBITS == 113 && LDBL_MAX_EXP == 0x4000 + +# define BIAS (LDBL_MAX_EXP - 1) static const float shift[2] = { -#if EXT_FRACBITS == 64 +# if EXT_FRACBITS == 64 0x1.0p63, -0x1.0p63 -#elif EXT_FRACBITS == 113 +# elif EXT_FRACBITS == 113 0x1.0p112, -0x1.0p112 -#elif EXT_FRACBITS == 112 - 0x1.0p111, -0x1.0p111 -#else -#error "Unsupported long double format" -#endif +# else +# error "Unsupported long double format" +# endif }; static const float zero[2] = { 0.0, -0.0 }; @@ -63,11 +65,11 @@ rintl(long double x) u.extu_ld = x; u.extu_ext.ext_frach &= ~0x80000000; - expsign = u.extu_ext.ext_sign; + expsign = GET_EXPSIGN(&u); ex = expsign & 0x7fff; - if (ex >= EXT_EXP_BIAS + EXT_FRACBITS - 1) { - if (ex == EXT_EXP_BIAS + EXT_FRACBITS) + if (ex >= BIAS + EXT_FRACBITS - 1) { + if (ex == BIAS + EXT_FRACBITS) return (x + x); /* Inf, NaN, or unsupported format */ return (x); /* finite and already an integer */ } @@ -87,9 +89,18 @@ rintl(long double x) * If the result is +-0, then it must have the same sign as x, but * the above calculation doesn't always give this. Fix up the sign. */ - if (ex < EXT_EXP_BIAS && x == 0.0L) + if (ex < BIAS && x == 0.0L) return (zero[sign]); return (x); } -#endif +# else + +long double +rintl(long double x) +{ + return rint(x); +} + +# endif +#endif /* __HAVE_LONG_DOUBLE */