Module Name: src Committed By: riastradh Date: Sat May 4 19:21:51 UTC 2024
Modified Files: src/lib/libm/src: s_rintl.c Log Message: s_rintl.c: Reduce FreeBSD diff and fix on ld128 platforms. EXT_FRACBITS, the number of bits in the _binary encoding_ that stores the trailing significand field, is never 113. In IEEE 754 binary128, it is 112, even though there are 113 bits of precision in the set of floating-point numbers -- the leading 1 bit is implicit in binary128. So ld128 platforms like aarch64 and sparc64 were skipping the real definition and just defining rintl as an alias for rint, which is wrong. In contrast, LDBL_MANT_DIG, the number of bits of precision in the set of floating-point numbers (p, in IEEE 754 parlance), is 113 in IEEE 754 binary128. This is also the constant used in FreeBSD libm anyway. So let's just use that instead of trying to translate it to our private EXT_FRACBITS (not defined in FreeBSD) with a fencepos terror. And delete the buggy rintl=rint alias. PR lib/58054 To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 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_rintl.c diff -u src/lib/libm/src/s_rintl.c:1.6 src/lib/libm/src/s_rintl.c:1.7 --- src/lib/libm/src/s_rintl.c:1.6 Tue Apr 2 18:39:51 2024 +++ src/lib/libm/src/s_rintl.c Sat May 4 19:21:51 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: s_rintl.c,v 1.6 2024/04/02 18:39:51 christos Exp $ */ +/* $NetBSD: s_rintl.c,v 1.7 2024/05/04 19:21:51 riastradh 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.6 2024/04/02 18:39:51 christos Exp $"); +__RCSID("$NetBSD: s_rintl.c,v 1.7 2024/05/04 19:21:51 riastradh Exp $"); #endif #include <float.h> @@ -39,20 +39,17 @@ __RCSID("$NetBSD: s_rintl.c,v 1.6 2024/0 #include "math.h" #include "math_private.h" -#ifdef __HAVE_LONG_DOUBLE +#define BIAS (LDBL_MAX_EXP - 1) -# 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 LDBL_MANT_DIG == 64 0x1.0p63, -0x1.0p63 -# elif EXT_FRACBITS == 113 +#elif LDBL_MANT_DIG == 113 0x1.0p112, -0x1.0p112 -# else -# error "Unsupported long double format" -# endif +#else +#error "Unsupported long double format" +#endif }; static const float zero[2] = { 0.0, -0.0 }; @@ -64,12 +61,11 @@ rintl(long double x) int ex, sign; u.extu_ld = x; - u.extu_ext.ext_frach &= ~0x80000000; expsign = GET_EXPSIGN(&u); ex = expsign & 0x7fff; - if (ex >= BIAS + EXT_FRACBITS - 1) { - if (ex == BIAS + EXT_FRACBITS) + if (ex >= BIAS + LDBL_MANT_DIG - 1) { + if (ex == BIAS + LDBL_MAX_EXP) return (x + x); /* Inf, NaN, or unsupported format */ return (x); /* finite and already an integer */ } @@ -94,13 +90,3 @@ rintl(long double x) return (x); } -# else - -long double -rintl(long double x) -{ - return rint(x); -} - -# endif -#endif /* __HAVE_LONG_DOUBLE */